Ejemplo n.º 1
0
 /**
  * Execute File Queries
  *
  * @param   string  $path  Path to sql file
  *
  * @return bool
  */
 public static function executeFileQueries($path)
 {
     if (JFile::exists($path)) {
         $queryString = file_get_contents($path);
         // Graceful exit and rollback if read not successful
         if ($queryString === false) {
             JLog::add(JText::_('JLIB_INSTALLER_ERROR_SQL_READBUFFER'), JLog::WARNING, 'jerror');
             return false;
         }
         $db = JFactory::getDbo();
         $queries = RHelperDatabase::splitSql($queryString);
         if (count($queries) == 0) {
             // No queries to process
             return 0;
         }
         // Process each query in the $queries array (split out of sql file).
         foreach ($queries as $query) {
             $query = trim($query);
             if ($query != '' && $query[0] != '#') {
                 $db->setQuery($query);
                 if (!$db->execute()) {
                     JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)), JLog::WARNING, 'jerror');
                     return false;
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * This function replaces a string identifier <var>$prefix</var> with the string held is the
  * <var>tablePrefix</var> class variable.
  *
  * @param   string  $sql           The SQL statement to prepare.
  * @param   string  $prefix        The common table prefix.
  * @param   bool    $insideQuotes  Replace prefix inside quotes too
  *
  * @return  string  The processed SQL statement.
  *
  * @since   11.1
  */
 public function replacePrefix($sql, $prefix = '#__', $insideQuotes = false)
 {
     // Basic check for translations
     if ($this->translate) {
         if ($parsedSql = RDatabaseSqlparserSqltranslation::buildTranslationQuery($sql, $prefix)) {
             return RHelperDatabase::replacePrefix($parsedSql, $this->tablePrefix, $prefix, $insideQuotes);
         }
     }
     return RHelperDatabase::replacePrefix($sql, $this->tablePrefix, $prefix, $insideQuotes);
 }
Ejemplo n.º 3
0
 /**
  * Method to process SQL updates previous to the install process
  *
  * @param   JInstallerAdapter  $parent  Class calling this method
  *
  * @return  boolean          True on success
  */
 public function preprocessUpdates($parent)
 {
     $manifest = $parent->get('manifest');
     if (isset($manifest->update)) {
         if (isset($manifest->update->attributes()->folder)) {
             $path = $manifest->update->attributes()->folder;
             if (isset($manifest->update->pre) && isset($manifest->update->pre->schemas)) {
                 $schemapaths = $manifest->update->pre->schemas->children();
                 if (count($schemapaths)) {
                     $sourcePath = $parent->getParent()->getPath('source');
                     // If it just upgraded redCORE to a newer version using RFactory for database, it forces using the redCORE database drivers
                     if (substr(get_class(JFactory::$database), 0, 1) == 'J' && $this->extensionElement != 'com_redcore') {
                         RFactory::$database = null;
                         JFactory::$database = null;
                         JFactory::$database = RFactory::getDbo();
                     }
                     $db = JFactory::getDbo();
                     $dbDriver = strtolower($db->name);
                     $schemapath = '';
                     if ($dbDriver == 'mysqli') {
                         $dbDriver = 'mysql';
                     }
                     foreach ($schemapaths as $entry) {
                         if (isset($entry->attributes()->type)) {
                             $uDriver = strtolower($entry->attributes()->type);
                             if ($uDriver == 'mysqli') {
                                 $uDriver = 'mysql';
                             }
                             if ($uDriver == $dbDriver) {
                                 $schemapath = (string) $entry;
                                 break;
                             }
                         }
                     }
                     if ($schemapath != '') {
                         $files = str_replace('.sql', '', JFolder::files($sourcePath . '/' . $path . '/' . $schemapath, '\\.sql$'));
                         usort($files, 'version_compare');
                         if (count($files)) {
                             foreach ($files as $file) {
                                 if (version_compare($file, $this->oldVersion) > 0) {
                                     $buffer = file_get_contents($sourcePath . '/' . $path . '/' . $schemapath . '/' . $file . '.sql');
                                     $queries = RHelperDatabase::splitSQL($buffer);
                                     if (count($queries)) {
                                         foreach ($queries as $query) {
                                             if ($query != '' && $query[0] != '#') {
                                                 $db->setQuery($query);
                                                 if (!$db->execute(true)) {
                                                     JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)), JLog::WARNING, 'jerror');
                                                     return false;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return true;
 }