Showing posts with label Open Source. Show all posts
Showing posts with label Open Source. Show all posts

Joomla automated backup to Cloud service

Well.. what's the use of the backup if you can't have it when you need it the most. I learned it the hard way. I had joomla website which is backup using Akeeba. Being on the free version, had to settle for cron job that triggers the backup. 

Following is the php snippet that trigger Akeeba backup profile.

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,
SITEURL.'/index.php?option=com_akeeba&view=backup&key='.
SECRETKEY.'&profile='.PROFILE);
curl_setopt($curl_handle,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($curl_handle,CURLOPT_MAXREDIRS,10000); 
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);


So far good. But to be real useful your backup needs to somewhere else. And what better than free cloud service like Dropbox or Google drive. Akeeba professional has out the box integration with Dropbox. For google Drive, you can get it done by following below steps

1. Firs you Need to create a Google Drive service account. Here is nice post that has detailed steps about it 
2. Get the latest google drive client API.
3. Use cp2goole that has helper methods to connect to Google drive
4. As I was on PHP 5.2 has to hack two things
  •   to get around finfo to get MIME type, use the system command//$fi = new finfo( FILEINFO_MIME ); //$mimeType = explode( ';', $fi->buffer(file_get_contents($path)));
    $mime = exec('file -b --mime-type ' . $path);
  •  Google_P12Signer.php , use the hack  
  • 5. then write script that is specific to your needs
    $dir = "backupsDir";
    $dh  = opendir($dir);
    $strToSreach = "NameOfThebackpFile".date("Ymd");
    printf($strToSreach);
    $nameOfFile = "";

    //Search the file
    while (false !== ($filename = readdir($dh))) {
       
      if( substr($filename,-4) == ".sql" && substr($filename,0,15) == $strToSreach ) {
            printf("Found the file: ".$filename);
            $nameOfFile = $filename;
        }
    }

    $path  = $dir."/".$nameOfFile;

    printf("zipping the file: ".$nameOfFile ."
    ");

    exec('gzip  ' . $path);

    $path  = $dir."/".$nameOfFile.".gz";


    printf( "Uploading %s to Google Drive\n", $path ."
    ");

    $service = new DriveServiceHelper( CLIENT_ID, SERVICE_ACCOUNT_NAME, KEY_PATH );
    And with this, if you run this script, your backup should get triggered, it should create a joomla backup with SQL file, it should get zipped and sent to your google drive and your should get an email that says Backup has been shared with your email account !




Changing Timezone for OpenBibilo Library system

OpenBibilo is an open source, simple, easy to use but a power library management system. It highly  suitable for low to mid volume libraries having low budget.

Last week I was implementing it for one of the library that wanted to use Singapore time. By default OpenBibilo follows the timezone of your hosted environment and there is no configuration to use a different timezone.

But you could easily change  it by following below steps:
  • Replace all occurances of sysdate() used in SQL queries to UTC timestamp and add the required offset. There are around 19 occurances in the PHP files ( for version 0.0.7) ,   e.g sysdate() -->  (UTC_TIMESTAMP()+ INTERVAL 8 HOUR)
  • There is one occurance of now(), that need to be replaced as well                                 e.g  now() -->(UTC_TIMESTAMP()+ INTERVAL 8 HOUR)
  • These steps takes care of database timezone,
  • One last step needed to maek sure your php dates are too on the same timezone. It can be done by setting timezone in shared\common.php. Just add below line in common.php date_default_timezone_set('Asia/Singapore');
That's it! Your timezone is set to whatever you want. Of course there is a better way of having this done in some common place. But this is quick way to set timezone at this point.

Joomla website weird problem of wrong URLs

I have one joomla site which was working fine for last 2 years. Suddenly I noticed that the most of the links on my site are weird. Some of the links content actual IP address of the website, some link contained ftp user name ( xx.com/~xx/index.php). I was sure that nothing has been changed no the website and had no clue why its happening.

Upon careful observation, I noticed that someone accessed the website using adding IP address and user name (~xx) as context root (it was same as website name..so he must have guessed it). And since the joomla caching was enabled, all the pages were cached that contained these links. any new hits were served using this pages and even newly cached pages were following same context root !

Once the problem was identified, solution was simple. Simply clear the cache/ (or disable it for time being).


Book Publishing on joomla website

1. Convert word to PDF using cutePDF write/PDF 999
2. Convert PDF to images using converter http://www.officeconvert.com/purchase.htm
3. Resize to 50% using fastStone
4. Display using any book modules. e.g.