public function preflight($type, $parent)
 {
     if (parent::preflight($type, $parent)) {
         $app = JFactory::getApplication();
         $configuration = JFactory::getConfig();
         $db = JFactory::getDbo();
         //check of curl is present
         if (!function_exists('curl_init') || !is_callable('curl_init')) {
             $msg = "<p>cURL extension is not enabled in your PHP installation. Please contact your hosting service provider</p>";
             if (version_compare(JVERSION, '3.0', 'gt')) {
                 JLog::add($msg, JLog::WARNING, 'jerror');
             } else {
                 JError::raiseWarning(100, $msg);
             }
             return false;
         }
         if (!function_exists('json_encode')) {
             $msg = "<p>JSON extension is not enabled in your PHP installation. Please contact your hosting service provider</p>";
             if (version_compare(JVERSION, '3.0', 'gt')) {
                 JLog::add($msg, JLog::WARNING, 'jerror');
             } else {
                 JError::raiseWarning(100, $msg);
             }
             return false;
         }
         //Get installed version
         //conservative method
         $xmlfile = JPATH_ADMINISTRATOR . '/components/com_j2store/manifest.xml';
         if (JFile::exists($xmlfile)) {
             $xml = JFactory::getXML($xmlfile);
             $version = (string) $xml->version;
             // abort if the current J2Store release is older
             if (version_compare($version, '3.0.0', 'lt')) {
                 $parent->getParent()->abort('You cannot install J2Store Version 3 over the old versions directly. A migration tool should be used first to migrate your previous store data.');
                 return false;
             }
         }
         //let us check the manifest cache as well. Cannot trust joomla installer
         $query = $db->getQuery(true);
         $query->select($db->quoteName('manifest_cache'))->from($db->quoteName('#__extensions'))->where($db->quoteName('element') . ' = ' . $db->quote('com_j2store'));
         $db->setQuery($query);
         $result = $db->loadResult();
         if ($result) {
             $manifest = json_decode($result);
             $version = $manifest->version;
             // abort if the current J2Store release is older
             if (version_compare($version, '3.0.0', 'lt')) {
                 $parent->getParent()->abort('You cannot install J2Store Version 3 over the old versions directly. A migration tool should be used first to migrate your previous store data.');
                 return false;
             }
         }
         //some times the user might have uninstalled v2 and try installing v3. Let us stop them doing so.
         //check for the prices table. It he has the prices table, then he is certainly having the old version.
         $db = JFactory::getDbo();
         //get the table list
         $alltables = $db->getTableList();
         //get prefix
         $prefix = $db->getPrefix();
         if (in_array($prefix . 'j2store_prices', $alltables)) {
             //user has the prices table. So the old version data might be there.
             $parent->getParent()->abort('Tables of J2Store Version 2.x found. If you have already installed J2Store Version 2, its tables might be there. If you do not have any data in those tables, then you can delete those tables via the phpmyadmin and then install J2store version 3. Otherwise, you will have to use our migration tool');
             return false;
         }
         //if we are here, then all checks are passed. Let us allow the user to install J2Store Version 3. Just make sure to remove the template overrides and incompatible modules
         //----file removal//
         //check in the template overrides.
         //first get the default template
         $query = "SELECT template FROM #__template_styles WHERE client_id = 0 AND home=1";
         $db->setQuery($query);
         $template = $db->loadResult();
         $template_path = JPATH_SITE . '/templates/' . $template . '/html';
         $com_override_path = $template_path . '/com_j2store';
         //j2store overrides - mycart
         if (JFolder::exists($com_override_path . '/carts')) {
             if (JFile::exists($com_override_path . '/carts/default_items.php')) {
                 if (!JFolder::move($com_override_path . '/carts/default_items.php', $com_override_path . '/carts/old_default_items.php')) {
                     $parent->getParent()->abort('Could not move file ' . $com_override_path . '/carts/default_items.php. It might be having old code. So please Check permissions and rename this file. ');
                     return false;
                 }
             }
         }
         if (JFolder::exists($com_override_path . '/cart')) {
             if (JFile::exists($com_override_path . '/cart/default_items.php')) {
                 if (!JFolder::move($com_override_path . '/cart/default_items.php', $com_override_path . '/cart/old_default_items.php')) {
                     $parent->getParent()->abort('Could not move file ' . $com_override_path . '/cart/default_items.php. It might be having old code. So please Check permissions and rename this file. ');
                     return false;
                 }
             }
         }
         //the following renaming should happen only during new installs. If its an update, then these issues probably taken care of.
         if ($type != 'update') {
             if (JFolder::exists($com_override_path . '/checkout')) {
                 if (JFile::exists($com_override_path . '/checkout/shipping_yes.php')) {
                     if (!JFolder::move($com_override_path . '/checkout/shipping_yes.php', $com_override_path . '/checkout/old_shipping_yes.php')) {
                         $parent->getParent()->abort('Could not move file ' . $com_override_path . '/checkout/shipping_yes.php. It might be having old code. So please Check permissions and rename this file. ');
                         return false;
                     }
                 }
             }
             //j2store overrides - products
             if (JFolder::exists($com_override_path . '/products')) {
                 if (JFolder::exists($com_override_path . '/old_products')) {
                     if (!JFolder::delete($com_override_path . '/old_products')) {
                         $parent->getParent()->abort('Could not delete folder ' . $com_override_path . '/products  Check permissions.');
                         return false;
                     }
                 }
                 if (!JFolder::move($com_override_path . '/products', $com_override_path . '/old_products')) {
                     $parent->getParent()->abort('Could not move folder ' . $com_override_path . '/products. Check permissions.');
                     return false;
                 }
             }
         }
         //----end of file removal//
         //all set. Lets rock..
         return true;
     } else {
         return false;
     }
 }
Beispiel #2
0
 /**
  * Joomla! pre-flight event. This runs before Joomla! installs or updates the component. This is our last chance to
  * tell Joomla! if it should abort the installation.
  *
  * @param   string     $type   Installation type (install, update, discover_install)
  * @param   JInstaller $parent Parent object
  *
  * @return  boolean  True to let the installation proceed, false to halt the installation
  */
 public function preflight($type, $parent)
 {
     // Check the minimum PHP version. Issue a very stern warning if it's not met.
     if (!empty($this->minimumPHPVersion)) {
         if (defined('PHP_VERSION')) {
             $version = PHP_VERSION;
         } elseif (function_exists('phpversion')) {
             $version = phpversion();
         } else {
             $version = '5.0.0';
             // all bets are off!
         }
         if (!version_compare($version, $this->minimumPHPVersion, 'ge')) {
             $msg = "<h1>Your PHP version is too old</h1>";
             $msg .= "<p>You need PHP {$this->minimumPHPVersion} or later to install this component. Support for PHP 5.3.3 and earlier versions has been discontinued by our company as we publicly announced in February 2013.</p>";
             $msg .= "<p>You are using PHP {$version} which is an extremely old version, released more than four years ago. This version contains known functional and security issues. The functional issues do not allow you to run Akeeba Backup and cannot be worked around. The security issues mean that your site <b>can be easily hacked</b> since that these security issues are well known for over four years.</p>";
             $msg .= "<p>You have to ask your host to immediately update your site to PHP {$this->minimumPHPVersion} or later, ideally the latest available version of PHP 5.4. If your host won't do that you are advised to switch to a better host to ensure the security of your site. If you have to stay with your current host for reasons beyond your control you can use Akeeba Backup 4.0.5 or earlier, available from our downloads page.</p>";
             JLog::add($msg, JLog::WARNING, 'jerror');
             return false;
         }
     }
     $result = parent::preflight($type, $parent);
     // Move the serverkey.php file from /akeeba to /engine to preserve the settings
     if ($result) {
         $componentPath = JPATH_ADMINISTRATOR . '/components/com_akeeba';
         $fromFile = $componentPath . '/akeeba/serverkey.php';
         $toFile = $componentPath . '/engine/serverkey.php';
         if (@file_exists($fromFile) && !@file_exists($toFile)) {
             $toPath = $componentPath . '/engine';
             if (class_exists('JLoader') && method_exists('JLoader', 'import')) {
                 JLoader::import('joomla.filesystem.folder');
                 JLoader::import('joomla.filesystem.file');
             }
             if (@is_dir($componentPath) && !@is_dir($toPath)) {
                 JFolder::create($toPath);
             }
             if (@is_dir($toPath)) {
                 JFile::copy($fromFile, $toFile);
             }
         }
     }
     return $result;
 }
 /**
  * Joomla! pre-flight event. This runs before Joomla! installs or updates the component. This is our last chance to
  * tell Joomla! if it should abort the installation.
  *
  * @param   string      $type    Installation type (install, update, discover_install)
  * @param   JInstaller  $parent  Parent object
  *
  * @return  boolean  True to let the installation proceed, false to halt the installation
  */
 public function preflight($type, $parent)
 {
     $this->minimumJoomlaVersion = '2.5.20';
     $result = parent::preflight($type, $parent);
     // PHP 5.2, Thou shall not pass | Anonymous function variable assignment example
     if ($result) {
         try {
             $date = new DateTime();
             $now = $date->getTimestamp();
             $greet = function ($name) {
                 return sprintf("Hello %s\r\n", $name);
             };
             $test = $greet('Extly');
         } catch (Exception $e) {
             $msg = "<p>You need PHP {$this->minimumPHPVersion} or later to install this component</p>";
             if (version_compare(JVERSION, '3.0', 'gt')) {
                 JLog::add($msg, JLog::WARNING, 'jerror');
             } else {
                 JError::raiseWarning(100, $msg);
             }
             return false;
         }
     }
     return $result;
 }