public function run($args) { $comp = new CComponent(); $ubconfig = array_merge(array('class' => 'UpdaterBehavior', 'isConsole' => true, 'noHalt' => true)); $comp->attachBehavior('UpdaterBehavior', $ubconfig); // The files directly involved in the update process: $updaterFiles = $comp->updaterFiles; // The web-based updater's action classes, which are defined separately: $updaterActions = $comp->getWebUpdaterActions(false); foreach ($updaterActions as $name => $properties) { $updaterFiles[] = UpdaterBehavior::classAliasPath($properties['class']); } echo "\$deps = "; var_export($updaterFiles); }
public function testRegenerateConfig() { $configFilename = UpdaterBehavior::$configFilename; // Copy of the original filename $testConfigFilename = 'X2Config-testRegen.php'; // Temporary new config filename $filesThatShouldBe600 = array('encryption.key', 'encryption.iv'); // Files for testing that permissions are set properly // Make test backups of the keys foreach (array('key', 'iv') as $cryptExt) { $cryptFile = Yii::app()->basePath . "/config/encryption.{$cryptExt}"; if (file_exists($cryptFile)) { rename($cryptFile, "{$cryptFile}.testbackup"); } } UpdaterBehavior::$configFilename = $testConfigFilename; copy(Yii::app()->basePath . "/config/{$configFilename}", Yii::app()->basePath . "/config/{$testConfigFilename}"); $this->assertTrue(file_exists(Yii::app()->basePath . '/config/' . UpdaterBehavior::$configFilename)); $ube = $this->instantiateUBe(); $newversion = '3.3.3.3.3.3.3.3.3.3.3.3.3'; $newupdaterVersion = '2.2.2.2.2.2.2.2.2'; $newbuildDate = 12345678910; $ube->regenerateConfig($newversion, $newupdaterVersion, $newbuildDate); include Yii::app()->basePath . "/config/" . $testConfigFilename; foreach (array('version', 'updaterVersion', 'buildDate') as $var) { $this->assertEquals(${"new{$var}"}, ${"{$var}"}, "Failed asserting that {$var} was set properly"); } // Test that permissions were set properly on the config/encryption files foreach ($filesThatShouldBe600 as $file) { $this->assertEquals(100600, decoct(fileperms(Yii::app()->basePath . "/config/{$file}")), "Failed asserting that {$file} had its permissions set properly."); } foreach ($filesThatShouldBe600 as $file) { // Forcefully change so we can properly test the permission-setting method chmod(Yii::app()->basePath . "/config/{$file}", octdec(100666)); } // Now, run the method: $ube->setConfigPermissions(100600); // Test that the permissions were set back to their proper values foreach ($filesThatShouldBe600 as $file) { $this->assertEquals(100600, decoct(fileperms(Yii::app()->basePath . "/config/{$file}")), "Failed asserting that {$file} had its permissions set properly."); } UpdaterBehavior::$configFilename = $configFilename; unlink(Yii::app()->basePath . "/config/{$testConfigFilename}"); // Restore test backups of the keys foreach (array('key', 'iv') as $cryptExt) { $cryptFile = Yii::app()->basePath . "/config/encryption.{$cryptExt}"; if (file_exists("{$cryptFile}.testbackup")) { rename("{$cryptFile}.testbackup", $cryptFile); } } }
/** * Magic setter for {@link noHalt}. Kept here so that console applications * can use it to stop more gracefully. * @param type $value */ public function setNoHalt($value) { self::$_noHalt = $value; }