[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_installer/models/ -> database.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Administrator
   4   * @subpackage    com_installer
   5   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   6   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  // No direct access.
  10  defined('_JEXEC') or die;
  11  
  12  // Import library dependencies
  13  JLoader::register('InstallerModel', dirname(__FILE__) . '/extension.php');
  14  JLoader::register('joomlaInstallerScript', JPATH_ADMINISTRATOR . '/components/com_admin/script.php');
  15  
  16  /**
  17   * Installer Manage Model
  18   *
  19   * @package        Joomla.Administrator
  20   * @subpackage    com_installer
  21   * @since        1.6
  22   */
  23  class InstallerModelDatabase extends InstallerModel
  24  {
  25      protected $_context = 'com_installer.discover';
  26  
  27      /**
  28       * Method to auto-populate the model state.
  29       *
  30       * Note. Calling getState in this method will result in recursion.
  31       *
  32       * @since    1.6
  33       */
  34  	protected function populateState($ordering = null, $direction = null)
  35      {
  36          $app = JFactory::getApplication();
  37          $this->setState('message', $app->getUserState('com_installer.message'));
  38          $this->setState('extension_message', $app->getUserState('com_installer.extension_message'));
  39          $app->setUserState('com_installer.message', '');
  40          $app->setUserState('com_installer.extension_message', '');
  41          parent::populateState('name', 'asc');
  42      }
  43  
  44      /**
  45       *
  46       * Fixes database problems
  47       */
  48  	public function fix()
  49      {
  50          $changeSet = $this->getItems();
  51          $changeSet->fix();
  52          $this->fixSchemaVersion($changeSet);
  53          $this->fixUpdateVersion();
  54          $installer = new joomlaInstallerScript();
  55          $installer->deleteUnexistingFiles();
  56          $this->fixDefaultTextFilters();
  57      }
  58  
  59      /**
  60       *
  61       * Gets the changeset object
  62       *
  63       * @return  JSchemaChangeset
  64       */
  65  	public function getItems()
  66      {
  67          $folder = JPATH_ADMINISTRATOR . '/components/com_admin/sql/updates/';
  68          $changeSet = JSchemaChangeset::getInstance(JFactory::getDbo(), $folder);
  69          return $changeSet;
  70      }
  71  
  72  	public function getPagination()
  73      {
  74          return true;
  75      }
  76  
  77      /**
  78       * Get version from #__schemas table
  79       *
  80       * @return  mixed  the return value from the query, or null if the query fails
  81       * @throws Exception
  82       */
  83  
  84  	public function getSchemaVersion() {
  85          $db = JFactory::getDbo();
  86          $query = $db->getQuery(true);
  87          $query->select('version_id')->from($db->qn('#__schemas'))
  88          ->where('extension_id = 700');
  89          $db->setQuery($query);
  90          $result = $db->loadResult();
  91          if ($db->getErrorNum()) {
  92              throw new Exception('Database error - getSchemaVersion');
  93          }
  94          return $result;
  95      }
  96  
  97      /**
  98       * Fix schema version if wrong
  99       *
 100       * @param JSchemaChangeSet
 101       *
 102       * @return   mixed  string schema version if success, false if fail
 103       */
 104  	public function fixSchemaVersion($changeSet)
 105      {
 106          // Get correct schema version -- last file in array
 107          $schema = $changeSet->getSchema();
 108          $db = JFactory::getDbo();
 109          $result = false;
 110  
 111          // Check value. If ok, don't do update
 112          $version = $this->getSchemaVersion();
 113          if ($version == $schema)
 114          {
 115              $result = $version;
 116          }
 117          else
 118          {
 119              // Delete old row
 120              $query = $db->getQuery(true);
 121              $query->delete($db->qn('#__schemas'));
 122              $query->where($db->qn('extension_id') . ' = 700');
 123              $db->setQuery($query);
 124              $db->query();
 125  
 126              // Add new row
 127              $query = $db->getQuery(true);
 128              $query->insert($db->qn('#__schemas'));
 129              $query->set($db->qn('extension_id') . '= 700');
 130              $query->set($db->qn('version_id') . '= ' . $db->q($schema));
 131              $db->setQuery($query);
 132              if ($db->query()) {
 133                  $result = $schema;
 134              }
 135          }
 136          return $result;
 137      }
 138  
 139      /**
 140       * Get current version from #__extensions table
 141       *
 142       * @return  mixed   version if successful, false if fail
 143       */
 144  
 145  	public function getUpdateVersion()
 146      {
 147          $table = JTable::getInstance('Extension');
 148          $table->load('700');
 149          $cache = new JRegistry($table->manifest_cache);
 150          return $cache->get('version');
 151      }
 152  
 153      /**
 154       * Fix Joomla version in #__extensions table if wrong (doesn't equal JVersion short version)
 155       *
 156       * @return   mixed  string update version if success, false if fail
 157       */
 158  	public function fixUpdateVersion()
 159      {
 160          $table = JTable::getInstance('Extension');
 161          $table->load('700');
 162          $cache = new JRegistry($table->manifest_cache);
 163          $updateVersion =  $cache->get('version');
 164          $cmsVersion = new JVersion();
 165          if ($updateVersion == $cmsVersion->getShortVersion())
 166          {
 167              return $updateVersion;
 168          }
 169          else
 170          {
 171              $cache->set('version', $cmsVersion->getShortVersion());
 172              $table->manifest_cache = $cache->toString();
 173              if ($table->store())
 174              {
 175                  return $cmsVersion->getShortVersion();
 176              }
 177              else
 178              {
 179                  return false;
 180              }
 181  
 182          }
 183      }
 184  
 185      /**
 186       * For version 2.5.x only
 187       * Check if com_config parameters are blank.
 188       *
 189       * @return  string  default text filters (if any)
 190       */
 191  	public function getDefaultTextFilters()
 192      {
 193          $table = JTable::getInstance('Extension');
 194          $table->load($table->find(array('name' => 'com_config')));
 195          return $table->params;
 196      }
 197      /**
 198       * For version 2.5.x only
 199       * Check if com_config parameters are blank. If so, populate with com_content text filters.
 200       *
 201       * @return  mixed  boolean true if params are updated, null otherwise
 202       */
 203  	public function fixDefaultTextFilters()
 204      {
 205          $table = JTable::getInstance('Extension');
 206          $table->load($table->find(array('name' => 'com_config')));
 207  
 208          // Check for empty $config and non-empty content filters
 209          if (!$table->params)
 210          {
 211              // Get filters from com_content and store if you find them
 212              $contentParams = JComponentHelper::getParams('com_content');
 213              if ($contentParams->get('filters'))
 214              {
 215                  $newParams = new JRegistry();
 216                  $newParams->set('filters', $contentParams->get('filters'));
 217                  $table->params = (string) $newParams;
 218                  $table->store();
 219                  return true;
 220              }
 221          }
 222      }
 223  }
 224  


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1