<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/* * ***********************************************************************
 * SQL App for Watchful
 * Copyright (c) 2006-2013 Anything Digital & Inetis
 * ************************************************************************
 * Watchful.li is a web site monitoring and security service.
 * 
 * Although Watchful.li is a paid service, this program is free software;
 * you can redistribute it and/or modify it under the terms of the GNU 
 * General Public License as published by the Free Software Foundation; 
 * either version 2 of the License, or (at your option) any later version.
 *
 * This header must not be removed. Additional contributions/changes
 * may be added to this header as long as no information is deleted.
 * ************************************************************************
 * Get the latest version of this program at: https://watchful.li
 * *********************************************************************** */
class plgWatchfulliAppsSqlAppInstallerScript
{

    public function postflight($route, $adapter)
    {
        if (stripos($route, 'install') !== false || stripos($route, 'update') !== false)
        {
            return $this->fixManifest($adapter);
        }
    }

    private function fixManifest($adapter)
    {
        $filesource = $adapter->get('parent')->getPath('source') . '/_manifest.xml';
        $filedest = $adapter->get('parent')->getPath('extension_root') . '/sqlApp.xml';

        if (!(JFile::copy($filesource, $filedest)))
        {
            JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_FAIL_COPY_FILE', $filesource, $filedest), JLog::WARNING, 'jerror');

            if (class_exists('JError'))
            {
                JError::raiseWarning(1, 'JInstaller::install: ' . JText::sprintf('Failed to copy file to', $filesource, $filedest));
            }
            else
            {
                throw new Exception('JInstaller::install: ' . JText::sprintf('Failed to copy file to', $filesource, $filedest));
            }
            return false;
        }

        return true;
    }

}
