/**
  * @testdox  getInstance() throws an Exception for an unsupported driver
  *
  * @covers   JSchemaChangeitem::getInstance
  *
  * @expectedException  RuntimeException
  */
 public function testGetInstanceThrowsAnExceptionForAnUnsupportedDriver()
 {
     $file = __DIR__ . '/stubs/mysql/3.5.0-2016-03-01.sql';
     $dbo = $this->getMockDatabase('Sqlite');
     $query = 'SELECT foo FROM bar';
     JSchemaChangeitem::getInstance($dbo, $file, $query);
 }
Esempio n. 2
0
 /**
  * Constructor: builds array of $changeItems by processing the .sql files in a folder.
  * The folder for the Joomla core updates is administrator/components/com_admin/sql/updates/<database>.
  *
  * @param   JDatabaseDriver  $db      The current database object
  * @param   string           $folder  The full path to the folder containing the update queries
  *
  * @since   2.5
  */
 public function __construct($db, $folder = null)
 {
     $this->db = $db;
     $this->folder = $folder;
     $updateFiles = $this->getUpdateFiles();
     $updateQueries = $this->getUpdateQueries($updateFiles);
     foreach ($updateQueries as $obj) {
         $this->changeItems[] = JSchemaChangeitem::getInstance($db, $obj->file, $obj->updateQuery);
     }
 }
Esempio n. 3
0
 /**
  * Constructor: builds array of $changeItems by processing the .sql files in a folder.
  * The folder for the Joomla core updates is `administrator/components/com_admin/sql/updates/<database>`.
  *
  * @param   JDatabaseDriver  $db      The current database object
  * @param   string           $folder  The full path to the folder containing the update queries
  *
  * @since   2.5
  */
 public function __construct($db, $folder = null)
 {
     $this->db = $db;
     $this->folder = $folder;
     $updateFiles = $this->getUpdateFiles();
     $updateQueries = $this->getUpdateQueries($updateFiles);
     foreach ($updateQueries as $obj) {
         $changeItem = JSchemaChangeitem::getInstance($db, $obj->file, $obj->updateQuery);
         if ($changeItem->queryType === 'UTF8CNV') {
             // Execute the special update query for utf8mb4 conversion status reset
             try {
                 $this->db->setQuery($changeItem->updateQuery)->execute();
             } catch (RuntimeException $e) {
                 JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
             }
         } else {
             // Normal change item
             $this->changeItems[] = $changeItem;
         }
     }
     // If on mysql, add a query at the end to check for utf8mb4 conversion status
     $serverType = $this->db->getServerType();
     if ($serverType == 'mysql') {
         // Let the update query be something harmless which should always succeed
         $tmpSchemaChangeItem = JSchemaChangeitem::getInstance($db, 'database.php', 'UPDATE ' . $this->db->quoteName('#__utf8_conversion') . ' SET ' . $this->db->quoteName('converted') . ' = 0;');
         // Set to not skipped
         $tmpSchemaChangeItem->checkStatus = 0;
         // Set the check query
         if ($this->db->hasUTF8mb4Support()) {
             $converted = 2;
             $tmpSchemaChangeItem->queryType = 'UTF8_CONVERSION_UTF8MB4';
         } else {
             $converted = 1;
             $tmpSchemaChangeItem->queryType = 'UTF8_CONVERSION_UTF8';
         }
         $tmpSchemaChangeItem->checkQuery = 'SELECT ' . $this->db->quoteName('converted') . ' FROM ' . $this->db->quoteName('#__utf8_conversion') . ' WHERE ' . $this->db->quoteName('converted') . ' = ' . $converted;
         // Set expected records from check query
         $tmpSchemaChangeItem->checkQueryExpected = 1;
         $tmpSchemaChangeItem->msgElements = array();
         $this->changeItems[] = $tmpSchemaChangeItem;
     }
 }