setState('message', $app->getUserState('com_installer.message')); $this->setState('extension_message', $app->getUserState('com_installer.extension_message')); $app->setUserState('com_installer.message', ''); $app->setUserState('com_installer.extension_message', ''); parent::populateState('name', 'asc'); } /** * Fixes database problems * * @return void */ public function fix() { if (!$changeSet = $this->getItems()) { return false; } $changeSet->fix(); $this->fixSchemaVersion($changeSet); $this->fixUpdateVersion(); $installer = new JoomlaInstallerScript; $installer->deleteUnexistingFiles(); $this->fixDefaultTextFilters(); } /** * Gets the changeset object * * @return JSchemaChangeset */ public function getItems() { $folder = JPATH_ADMINISTRATOR . '/components/com_admin/sql/updates/'; try { $changeSet = JSchemaChangeset::getInstance(JFactory::getDbo(), $folder); } catch (RuntimeException $e) { JFactory::getApplication()->enqueueMessage($e->getMessage(), 'warning'); return false; } return $changeSet; } /** * Method to get a JPagination object for the data set. * * @return boolean * * @since 12.2 */ public function getPagination() { return true; } /** * Get version from #__schemas table * * @return mixed the return value from the query, or null if the query fails * * @throws Exception */ public function getSchemaVersion() { $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select('version_id') ->from($db->quoteName('#__schemas')) ->where('extension_id = 700'); $db->setQuery($query); $result = $db->loadResult(); return $result; } /** * Fix schema version if wrong * * @param JSchemaChangeSet $changeSet Schema change set * * @return mixed string schema version if success, false if fail */ public function fixSchemaVersion($changeSet) { // Get correct schema version -- last file in array $schema = $changeSet->getSchema(); $db = JFactory::getDbo(); $result = false; // Check value. If ok, don't do update $version = $this->getSchemaVersion(); if ($version == $schema) { $result = $version; } else { // Delete old row $query = $db->getQuery(true) ->delete($db->quoteName('#__schemas')) ->where($db->quoteName('extension_id') . ' = 700'); $db->setQuery($query); $db->execute(); // Add new row $query->clear() ->insert($db->quoteName('#__schemas')) ->set($db->quoteName('extension_id') . '= 700') ->set($db->quoteName('version_id') . '= ' . $db->quote($schema)); $db->setQuery($query); if ($db->execute()) { $result = $schema; } } return $result; } /** * Get current version from #__extensions table * * @return mixed version if successful, false if fail */ public function getUpdateVersion() { $table = JTable::getInstance('Extension'); $table->load('700'); $cache = new JRegistry($table->manifest_cache); return $cache->get('version'); } /** * Fix Joomla version in #__extensions table if wrong (doesn't equal JVersion short version) * * @return mixed string update version if success, false if fail */ public function fixUpdateVersion() { $table = JTable::getInstance('Extension'); $table->load('700'); $cache = new JRegistry($table->manifest_cache); $updateVersion = $cache->get('version'); $cmsVersion = new JVersion; if ($updateVersion == $cmsVersion->getShortVersion()) { return $updateVersion; } else { $cache->set('version', $cmsVersion->getShortVersion()); $table->manifest_cache = $cache->toString(); if ($table->store()) { return $cmsVersion->getShortVersion(); } else { return false; } } } /** * For version 2.5.x only * Check if com_config parameters are blank. * * @return string default text filters (if any) */ public function getDefaultTextFilters() { $table = JTable::getInstance('Extension'); $table->load($table->find(array('name' => 'com_config'))); return $table->params; } /** * For version 2.5.x only * Check if com_config parameters are blank. If so, populate with com_content text filters. * * @return mixed boolean true if params are updated, null otherwise */ public function fixDefaultTextFilters() { $table = JTable::getInstance('Extension'); $table->load($table->find(array('name' => 'com_config'))); // Check for empty $config and non-empty content filters if (!$table->params) { // Get filters from com_content and store if you find them $contentParams = JComponentHelper::getParams('com_content'); if ($contentParams->get('filters')) { $newParams = new JRegistry; $newParams->set('filters', $contentParams->get('filters')); $table->params = (string) $newParams; $table->store(); return true; } } } }