Changeset 10737
- Timestamp:
- Feb 10, 2009, 6:37:46 PM (13 years ago)
- Location:
- OpenPNE3/trunk
- Files:
-
- 1 added
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE3/trunk/lib/migration/opMigration.class.php
r10732 r10737 16 16 * @author Kousuke Ebihara <ebihara@tejimaya.com> 17 17 */ 18 abstractclass opMigration extends Doctrine_Migration18 class opMigration extends Doctrine_Migration 19 19 { 20 20 protected $targetName = ''; … … 30 30 { 31 31 $names = $this->dbManager->getNames(); 32 $connectionName = array_shift($ connectionName);32 $connectionName = array_shift($names); 33 33 } 34 34 $this->database = $this->dbManager->getDatabase($connectionName); … … 90 90 $this->$method(); 91 91 } 92 93 /** 94 * @see Doctrine_Migration 95 */ 96 protected function createMigrationTable() 97 { 98 // do nothing 99 } 100 101 /** 102 * @see Doctrine_Migration 103 */ 104 protected function setCurrentVersion($number) 105 { 106 SnsConfigPeer::set($this->targetName.'_revision', $number); 107 } 108 109 /** 110 * @see Doctrine_Migration 111 */ 112 public function getCurrentVersion() 113 { 114 return SnsConfigPeer::get($this->targetName.'_revision', 0); 115 } 116 117 /** 118 * @see Doctrine_Migration 119 */ 120 public function hasMigrated() 121 { 122 return is_null(SnsConfigPeer::get($this->targetName.'_revision')); 123 } 124 125 /** 126 * @see Doctrine_Migration 127 */ 128 public function loadMigrationClassesFromDirectory() 129 { 130 $classes = get_declared_classes(); 131 132 foreach ((array)$this->_migrationClassesDirectory as $dir) 133 { 134 $files = sfFinder::type('file')->name('*.php')->in($dir); 135 $iterator = new CompareMigrateDirectoryVersionFilterIterator($files, str_replace('-dev', '', OPENPNE_VERSION)); 136 foreach ($iterator as $file) 137 { 138 if (!in_array(basename($file), $this->_loadedMigrations)) 139 { 140 require_once $file; 141 142 $requiredClass = array_diff(get_declared_classes(), $classes); 143 $requiredClass = end($requiredClass); 144 if ($requiredClass) 145 { 146 $this->_loadedMigrations[$requiredClass] = basename($file); 147 } 148 } 149 } 150 } 151 } 92 152 } 153 154 class CompareMigrateDirectoryVersionFilterIterator extends FilterIterator 155 { 156 protected $limitVersion; 157 158 public function __construct(array $fileList, $limitVersion) 159 { 160 $this->limitVersion = $limitVersion; 161 162 return parent::__construct(new ArrayIterator($fileList)); 163 } 164 165 public function accept() 166 { 167 $version = basename(dirname($this->current())); 168 return version_compare($version, $this->limitVersion, '<='); 169 } 170 } -
OpenPNE3/trunk/lib/task/openpneMigrateTask.class.php
r10734 r10737 9 9 */ 10 10 11 class openpne UpdateTask extends sfPropelBaseTask11 class openpneMigrateTask extends sfPropelBaseTask 12 12 { 13 13 protected function configure() 14 14 { 15 15 $this->namespace = 'openpne'; 16 $this->name = ' update';16 $this->name = 'migrate'; 17 17 18 18 require sfConfig::get('sf_data_dir').'/version.php'; … … 20 20 $this->addArguments(array( 21 21 new sfCommandArgument('name', sfCommandArgument::OPTIONAL, 'The plugin name or "OpenPNE"', 'OpenPNE'), 22 new sfCommandArgument('before-version', sfCommandArgument::OPTIONAL, '', '3.0.0'),23 new sfCommandArgument('after-version', sfCommandArgument::OPTIONAL, '', OPENPNE_VERSION),24 22 )); 25 23 26 24 $this->addOptions(array( 25 new sfCommandOption('openpne-version', 'v', sfCommandOption::PARAMETER_OPTIONAL, 'To version', OPENPNE_VERSION), 26 new sfCommandOption('revision', 'r', sfCommandOption::PARAMETER_OPTIONAL, 'To revision'), 27 27 new sfCommandOption('no-build-model', null, sfCommandOption::PARAMETER_NONE, 'Do not build model classes'), 28 28 )); … … 30 30 $this->briefDescription = 'update OpenPNE'; 31 31 $this->detailedDescription = <<<EOF 32 The [openpne: update|INFO] task updates OpenPNE and/or plugin.32 The [openpne:migrade|INFO] task upgrades or downgrades OpenPNE and/or plugin. 33 33 Call it with: 34 34 35 [./symfony openpne: update|INFO]35 [./symfony openpne:migrade|INFO] 36 36 EOF; 37 37 } … … 40 40 { 41 41 $databaseManager = new sfDatabaseManager($this->configuration); 42 43 $dir = sfConfig::get('sf_lib_dir').'/update'; 44 $prefix = 'op'; 45 if ('OpenPNE' !== $arguments['name']) 46 { 47 $dir = sfConfig::get('sf_plugins_dir').'/'.$arguments['name'].'/lib/update'; 48 $prefix = $arguments['name']; 49 } 50 51 $beforeVersion = self::formatVersion($arguments['before-version']); 52 $afterVersion = self::formatVersion($arguments['after-version']); 53 54 $files = sfFinder::type('file')->not_name('opUpdate.class.php')->not_name('opUpdateDoctrineMigrationProcess.class.php')->in($dir); 55 $files = array_map(create_function('$path', 'return basename($path);'), $files); 56 usort($files, array(get_class($this), 'sortBeforeVersions')); 57 foreach ($files as $file) 58 { 59 $versions = explode('_to_', str_replace('.php', '', $file), 2); 60 $_before = self::formatVersion($versions[0]); 61 $_after = self::formatVersion($versions[1]); 62 63 if (version_compare($beforeVersion, $_after, '<=') && version_compare($afterVersion, $_after, '>=')) 64 { 65 $className = $prefix.'Update_'.str_replace('.php', '', $file); 66 $this->logSection('execute', $className); 67 require_once $dir.'/'.$file; 68 $obj = new $className($this->dispatcher, $databaseManager); 69 $obj->doUpdate(); 70 } 71 } 42 $migration = new opMigration($this->dispatcher, $databaseManager); 43 $migration->migrate(); 72 44 73 45 if (!$options['no-build-model']) … … 75 47 $this->buildModel(); 76 48 } 77 }78 79 static public function sortBeforeVersions($name1, $name2)80 {81 $_versions = explode('_to_', str_replace('.php', '', $name1), 2);82 $version1 = array_shift($_versions);83 $_versions = explode('_to_', str_replace('.php', '', $name2), 2);84 $version2 = array_shift($_versions);85 86 return version_compare(self::formatVersion($version1), self::formatVersion($version2));87 }88 89 static public function formatVersion($version)90 {91 $_searches = array('-', '_', '+');92 $version = str_replace($_searches, '.', $version);93 94 $pos = strpos($version, '.dev.');95 if (false !== $pos)96 {97 $time = substr($version, $pos + strlen('.dev.'));98 $datetime = new DateTime($time);99 $version = substr($version, 0, $pos + strlen('.dev.')).$datetime->format('U');100 }101 102 return $version;103 49 } 104 50
Note: See TracChangeset
for help on using the changeset viewer.