#!/usr/bin/perl -w

# for i in `ls unrwa_*`; do echo $i;cp -p /tmp/fixPortal /tmp/urt; perl -pi -e "s/_MY_SITE_/$i/" /tmp/urt; sudo /tmp/urt; done;
# #

use lib '/www/opals/module';
#use Opals::Context("/etc/opals/conf/oc_oc");
use Opals::Context("/etc/opals/conf/unrwa_55472");
#use Opals::Context("/etc/opals/conf/_MY_SITE_");
use strict;
use DBI;
use JSON;
use POSIX qw(
    ceil
);
my $dbh = Opals::Context->dbh();
END {
    if ($dbh) {
        $dbh->disconnect();
    }
}

$| = 1;
# Codes start...

my $aboutUs="";
my $sth = $dbh->prepare(<<_SQL_);
select fileData from opl_file where fileName='portalJson' ; 
_SQL_

my $sth_prop = $dbh->prepare(<<_SQL_);
select convert(cast(val as binary) using utf8) val from opl_portletProp where pid=1
_SQL_


    $sth->execute;

    my ($json)= $sth->fetchrow_array;
    my $portal = decode_json($json);

    $sth_prop->execute();
    my ($about)=$sth_prop->fetchrow_array;
    $portal->{"aboutUs"}=$about;

     $json = to_json($portal);
     open OUT,">/tmp/ss"; print OUT $json;close OUT;


    open IN,"</tmp/ss";
    my $dd="";
    while(<IN>){
		$dd .= $_;
    }
    close IN;
    $dbh->do("update opl_file set fileName='portalJson_bk' where fileName='portalJson'");
   $sth = $dbh->prepare(<<_STH_);
replace into  opl_file
set     mimeType = 'text/plain',
        fileData = ?,
        fileType='text/javascript',
        fileName='portalJson',
        fRealName='portalJson'
_STH_

  $sth->execute($dd);
#print "$json\n";
    $sth->finish;




#////////////////////////////////////////////////////////////////////////////
