Ejemplo n.º 1
0
 /**
  * Prevent downgrades to Kunena 1.7 and older releases
  */
 public function onExtensionBeforeUpdate($type, $manifest)
 {
     if ($type != 'component') {
         return true;
     }
     // Generate component name
     $name = strtolower(JFilterInput::getInstance()->clean((string) $manifest->name, 'cmd'));
     $element = substr($name, 0, 4) == "com_" ? $name : "com_{$name}";
     if ($element != 'com_kunena') {
         return true;
     }
     // Kunena 2.0.0-BETA2 and later support this feature in their installer
     if (version_compare($manifest->version, '2.0.0', '>=')) {
         return true;
     }
     // Check if we can downgrade to the current version
     if (class_exists('KunenaInstaller') && KunenaInstaller::canDowngrade($manifest->version)) {
         return true;
     }
     // Old version detected: emulate failed installation
     $app = JFactory::getApplication();
     $app->enqueueMessage(sprintf('Sorry, it is not possible to downgrade Kunena %s to version %s.', KunenaForum::version(), $manifest->version), 'warning');
     $app->enqueueMessage(JText::_('JLIB_INSTALLER_ABORT_COMP_INSTALL_CUSTOM_INSTALL_FAILURE'), 'error');
     $app->enqueueMessage(JText::sprintf('COM_INSTALLER_MSG_UPDATE_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($type))));
     $app->redirect('index.php?option=com_installer');
     return true;
 }
Ejemplo n.º 2
0
 protected function checkKunena($version)
 {
     $app = JFactory::getApplication();
     // Always load Kunena API if it exists.
     $api = JPATH_ADMINISTRATOR . '/components/com_kunena/api.php';
     if (file_exists($api)) {
         require_once $api;
     }
     // Do not install over Git repository (K1.6+).
     if (class_exists('Kunena') && method_exists('Kunena', 'isSvn') && Kunena::isSvn() || class_exists('KunenaForum') && method_exists('KunenaForum', 'isDev') && KunenaForum::isDev()) {
         $app->enqueueMessage('Oops! You should not install Kunena over your Git reporitory!', 'notice');
         return false;
     }
     $db = JFactory::getDBO();
     // Check if Kunena can be found from the database
     $table = $db->getPrefix() . 'kunena_version';
     $db->setQuery("SHOW TABLES LIKE {$db->quote($table)}");
     if ($db->loadResult() != $table) {
         return true;
     }
     // Get installed Kunena version
     $db->setQuery("SELECT version FROM {$db->quoteName($table)} ORDER BY `id` DESC", 0, 1);
     $installed = $db->loadResult();
     if (!$installed) {
         return true;
     }
     // Always allow upgrade to the newer version
     if (version_compare($version, $installed, '>=')) {
         return true;
     }
     // Check if we can downgrade to the current version
     if (class_exists('KunenaInstaller')) {
         if (KunenaInstaller::canDowngrade($version)) {
             return true;
         }
     } else {
         // Workaround when Kunena files were removed to allow downgrade between bugfix versions.
         $major = preg_replace('/(\\d+.\\d+)\\..*$/', '\\1', $version);
         if (version_compare($installed, $major, '>')) {
             return true;
         }
     }
     $app->enqueueMessage(sprintf('Sorry, it is not possible to downgrade Kunena %s to version %s.', $installed, $version), 'notice');
     return false;
 }