コード例 #1
0
ファイル: PluginsService.php プロジェクト: kant312/sop
 /**
  * If the plugin already had a migrations folder with migrations in it, let's save them in the db.
  *
  * @param int    $pluginId
  * @param string $pluginHandle
  *
  * @throws Exception
  */
 private function _savePluginMigrations($pluginId, $pluginHandle)
 {
     $migrationsFolder = craft()->path->getPluginsPath() . mb_strtolower($pluginHandle) . '/migrations/';
     if (IOHelper::folderExists($migrationsFolder)) {
         $migrations = array();
         $migrationFiles = IOHelper::getFolderContents($migrationsFolder, false, "(m(\\d{6}_\\d{6})_.*?)\\.php");
         if ($migrationFiles) {
             foreach ($migrationFiles as $file) {
                 if (IOHelper::fileExists($file)) {
                     $migration = new MigrationRecord();
                     $migration->version = IOHelper::getFileName($file, false);
                     $migration->applyTime = DateTimeHelper::currentUTCDateTime();
                     $migration->pluginId = $pluginId;
                     $migrations[] = $migration;
                 }
             }
             foreach ($migrations as $migration) {
                 if (!$migration->save()) {
                     throw new Exception(Craft::t('There was a problem saving to the migrations table: ') . $this->_getFlattenedErrors($migration->getErrors()));
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * Populates the migrations table with the base migration.
  *
  * @throws Exception
  */
 private function _populateMigrationTable()
 {
     $migration = new MigrationRecord();
     $migration->version = craft()->migrations->getBaseMigration();
     $migration->applyTime = DateTimeHelper::currentUTCDateTime();
     if ($migration->save()) {
         Craft::log('Migration table populated successfully.');
     } else {
         Craft::log('Could not populate the migration table.', LogLevel::Error);
         throw new Exception(Craft::t('There was a problem saving to the migrations table:') . $this->_getFlattenedErrors($migration->getErrors()));
     }
 }
コード例 #3
0
 /**
  * Populates the migrations table with the base migration plus any existing ones from app/migrations.
  *
  * @throws Exception
  * @return null
  */
 private function _populateMigrationTable()
 {
     $migrations = array();
     // Add the base one.
     $migration = new MigrationRecord();
     $migration->version = craft()->migrations->getBaseMigration();
     $migration->applyTime = DateTimeHelper::currentUTCDateTime();
     $migrations[] = $migration;
     $migrationsFolder = craft()->path->getAppPath() . 'migrations/';
     $migrationFiles = IOHelper::getFolderContents($migrationsFolder, false, "(m(\\d{6}_\\d{6})_.*?)\\.php");
     if ($migrationFiles) {
         foreach ($migrationFiles as $file) {
             if (IOHelper::fileExists($file)) {
                 $migration = new MigrationRecord();
                 $migration->version = IOHelper::getFileName($file, false);
                 $migration->applyTime = DateTimeHelper::currentUTCDateTime();
                 $migrations[] = $migration;
             }
         }
         foreach ($migrations as $migration) {
             if (!$migration->save()) {
                 Craft::log('Could not populate the migration table.', LogLevel::Error);
                 throw new Exception(Craft::t('There was a problem saving to the migrations table: ') . $this->_getFlattenedErrors($migration->getErrors()));
             }
         }
     }
     Craft::log('Migration table populated successfully.');
 }
コード例 #4
0
 /**
  * Initializes the application component.
  *
  * @throws Exception
  * @return bool|null
  */
 public function init()
 {
     $migration = new MigrationRecord('install');
     $this->_migrationTable = $migration->getTableName();
 }