コード例 #1
0
 public static function getComponentVersion()
 {
     $packages = MageBridgeUpdateHelper::getPackageList();
     foreach ($packages as $package) {
         if ($package['type'] == 'component') {
             return MageBridgeUpdateHelper::getCurrentVersion($package);
         }
     }
 }
コード例 #2
0
ファイル: update.php プロジェクト: apiceweb/MageBridgeCore
 /**
  * Get versioning information of all packages
  *
  * @param null
  * @return array
  */
 public static function getData()
 {
     $data = array();
     foreach (MageBridgeUpdateHelper::getPackageList() as $package) {
         $package['current_version'] = MageBridgeUpdateHelper::getCurrentVersion($package);
         $package['update'] = false;
         $data[] = $package;
     }
     return $data;
 }
コード例 #3
0
ファイル: update.php プロジェクト: apiceweb/MageBridgeCore
 /**
  * Method to upgrade a specific extension
  *
  * @package MageBridge
  * @access public
  * @param string $exension_name
  * @return bool
  */
 private function update($extension_name = null)
 {
     // Do not continue if the extension name is empty
     if ($extension_name == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_NO_EXTENSION'));
         return false;
     }
     // Fetch a list of available packages
     $packages = MageBridgeUpdateHelper::getPackageList();
     foreach ($packages as $package) {
         if ($package['name'] == $extension_name) {
             $extension = $package;
             break;
         }
     }
     // Do not continue if the extension does not appear from the list
     if ($extension == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_UNKNOWN_EXTENSION'));
         return false;
     }
     // Premature check for the component-directory to be writable
     if ($extension['type'] == 'component' && JFactory::getConfig()->get('ftp_enable') == 0) {
         if (is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components/' . $extension['name'])) {
             JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DIR_NOT_WRITABLE', JPATH_ADMINISTRATOR . '/components/' . $extension['name']));
             return false;
         } else {
             if (!is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components')) {
                 JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DIR_NOT_WRITABLE', JPATH_ADMINISTRATOR . '/components'));
                 return false;
             }
         }
     }
     // Construct the update URL
     $extension_uri = $extension['name'];
     $extension_uri .= '_j25';
     $extension_uri .= '.' . MagebridgeModelConfig::load('update_format');
     $extension_url = $this->getUrl($extension_uri);
     // Either use fopen() or CURL
     if (ini_get('allow_url_fopen') == 1 && MagebridgeModelConfig::load('update_method') == 'joomla') {
         $package_file = JInstallerHelper::downloadPackage($extension_url, $extension_uri);
     } else {
         $package_file = MageBridgeUpdateHelper::downloadPackage($extension_url, $extension_uri);
     }
     // Simple check for the result
     if ($package_file == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DOWNLOAD_FAILED', $extension_uri));
         return false;
     }
     // Check if the downloaded file exists
     $tmp_path = JFactory::getConfig()->get('tmp_path');
     $package_path = $tmp_path . '/' . $package_file;
     if (!is_file($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NOT_EXISTS', $package_path));
         return false;
     }
     // Check if the file is readable
     if (!is_readable($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NOT_READABLE', $package_path));
         return false;
     }
     // Check if the downloaded file is abnormally small (so it might just contain a simple warning-text)
     if (filesize($package_path) < 128) {
         $contents = @file_get_contents($package_path);
         if (empty($contents)) {
             JError::raiseWarning('MB', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_EMPTY'));
             return false;
         } else {
             if (preg_match('/^Restricted/', $contents)) {
                 JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_NO_ACCESS'));
                 return false;
             }
         }
         JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NO_ARCHIVE', $package_path));
         return false;
     }
     // Now we assume this is an archive, so let's unpack it
     $package = JInstallerHelper::unpack($package_path);
     if ($package == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_GONE', $extension['name']));
         return false;
     }
     // Quick workaround to prevent Koowa proxying the database
     if (class_exists('KInput')) {
         KInput::set('option', 'com_installer', 'get');
     }
     // Call the actual installer to install the package
     $installer = JInstaller::getInstance();
     if ($installer->install($package['dir']) == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FAILED', $extension['name']));
         return false;
     }
     // Get the name of downloaded package
     if (!is_file($package['packagefile'])) {
         $package['packagefile'] = JFactory::getConfig()->get('tmp_path') . '/' . $package['packagefile'];
     }
     // Clean up the installation
     @JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     // Post install procedure
     if (isset($extension['post_install_query'])) {
         $query = trim($extension['post_install_query']);
         if (!empty($query)) {
             $db = JFactory::getDBO();
             $db->setQuery($query);
             try {
                 $db->execute();
             } catch (Exception $e) {
                 JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_POSTQUERY_FAILED', $db->getErrorMsg()));
                 return false;
             }
             if ($db->getErrorMsg()) {
                 JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_POSTQUERY_FAILED', $db->getErrorMsg()));
                 return false;
             }
         }
     }
     return true;
 }
コード例 #4
0
 private function update($extension_name = null)
 {
     // Do not continue if the extension name is empty
     if ($extension_name == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('No extension specified'));
         return false;
     }
     // Fetch a list of available packages
     $packages = MageBridgeUpdateHelper::getPackageList();
     foreach ($packages as $package) {
         if ($package['name'] == $extension_name) {
             $extension = $package;
             break;
         }
     }
     // Do not continue if the extension does not appear from the list
     if ($extension == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('Unknown extension'));
         return false;
     }
     // Premature check for the component-directory to be writable
     if ($extension['type'] == 'component' && JFactory::getConfig()->getValue('ftp_enable') == 0) {
         if (is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components/' . $extension['name'])) {
             JError::raiseWarning('SOME_ERROR_CODE', JText::_('Component directory is not writable'));
             return false;
         } else {
             if (!is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components')) {
                 JError::raiseWarning('SOME_ERROR_CODE', JText::_('Components folder is not writable'));
                 return false;
             }
         }
     }
     // Construct the update URL
     $extension_uri = $extension['name'];
     $extension_uri .= MageBridgeHelper::isJoomla15() ? '_j15' : '_j25';
     $extension_uri .= '.' . MagebridgeModelConfig::load('update_format');
     $extension_url = $this->getUrl($extension_uri);
     // Either use fopen() or CURL
     if (ini_get('allow_url_fopen') == 1 && MagebridgeModelConfig::load('update_method') == 'joomla') {
         $package_file = JInstallerHelper::downloadPackage($extension_url, $extension_uri);
     } else {
         $package_file = MageBridgeUpdateHelper::downloadPackage($extension_url, $extension_uri);
     }
     // Simple check for the result
     if ($package_file == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Failed to download update for %s', $extension_uri));
         return false;
     }
     // Check if the downloaded file exists
     $tmp_path = JFactory::getConfig()->getValue('config.tmp_path');
     $package_path = $tmp_path . '/' . $package_file;
     if (!is_file($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('File %s does not exist', $package_path));
         return false;
     }
     // Check if the file is readable
     if (!is_readable($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('File %s is not readable', $package_path));
         return false;
     }
     // Check if the downloaded file is abnormally small (so it might just contain a simple warning-text)
     if (filesize($package_path) < 128) {
         $contents = @file_get_contents($package_path);
         if (empty($contents)) {
             JError::raiseWarning('MB', JText::sprintf('Valid archive but empty content.'));
             return false;
         } else {
             if (preg_match('/^Restricted/', $contents)) {
                 JError::raiseWarning('MB', JText::sprintf('Not allowed to access updates.'));
                 return false;
             }
         }
         JError::raiseWarning('MB', JText::sprintf('File %s is not a valid archive', $package_path));
         return false;
     }
     // Now we assume this is an archive, so let's unpack it
     $package = JInstallerHelper::unpack($package_path);
     if ($package == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Unable to find update for %s on local filesystem', $extension['name']));
         return false;
     }
     // Quick workaround to prevent Koowa proxying the database
     if (class_exists('KInput')) {
         KInput::set('option', 'com_installer', 'get');
     }
     // Call the actual installer to install the package
     $installer = JInstaller::getInstance();
     if ($installer->install($package['dir']) == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Failed to install %s', $extension['name']));
         return false;
     }
     // Get the name of downloaded package
     if (!is_file($package['packagefile'])) {
         $package['packagefile'] = JFactory::getConfig()->getValue('config.tmp_path') . '/' . $package['packagefile'];
     }
     // Clean up the installation
     @JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     // Post install procedure
     if (isset($extension['post_install_query'])) {
         $query = trim($extension['post_install_query']);
         if (!empty($query)) {
             $db = JFactory::getDBO();
             $db->setQuery($query);
             $db->query();
             if ($db->getErrorMsg()) {
                 JError::raiseWarning('MB', JText::sprintf('Post install query failed: %s', $db->getErrorMsg()));
                 return false;
             }
         }
     }
     return true;
 }
コード例 #5
0
    die('Illegal access');
}
$_SERVER['HTTP_HOST'] = null;
// System definitions
define('_JEXEC', 1);
define('JPATH_BASE', dirname(dirname(dirname(dirname(__FILE__)))));
defined('_JEXEC') or die;
// Include the Joomla! framework
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
// Initialize Joomla!
$mainframe = JFactory::getApplication('administrator');
$mainframe->initialise();
// Include the needed MageBridge classes
require_once JPATH_SITE . '/components/com_magebridge/helpers/loader.php';
require_once JPATH_ADMINISTRATOR . '/components/com_magebridge/models/update.php';
// Set the hostname to enable license checks
$_SERVER['HTTP_HOST'] = MagebridgeModelConfig::load('host');
// Initialize the updater
$update = new MagebridgeModelUpdate();
$packages = MageBridgeUpdateHelper::getPackageList();
$files = array();
// Add current packages to the update list
foreach ($packages as $package) {
    if (MageBridgeUpdateHelper::getCurrentVersion($package) == true) {
        $files[] = $package['name'];
    }
}
// Perform the actual update
@$update->updateAll($files);
// End