| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfYamlUpgrade extends sfUpgrade |
|---|
| 20 |
{ |
|---|
| 21 |
public function upgrade() |
|---|
| 22 |
{ |
|---|
| 23 |
$specVersion = sfYaml::getSpecVersion(); |
|---|
| 24 |
|
|---|
| 25 |
$queue = array(); |
|---|
| 26 |
$success = true; |
|---|
| 27 |
|
|---|
| 28 |
$finder = sfFinder::type('file')->name('*.yml')->prune('vendor'); |
|---|
| 29 |
foreach ($finder->in(sfConfig::get('sf_root_dir')) as $file) |
|---|
| 30 |
{ |
|---|
| 31 |
|
|---|
| 32 |
$original = file_get_contents($file); |
|---|
| 33 |
$upgraded = sfToolkit::pregtr($original, array( |
|---|
| 34 |
'/^([^:]+: +)(?:on|y(?:es)?|\+)(\s*(#.*)?)$/im' => '\\1true\\2', |
|---|
| 35 |
'/^([^:]+: +)(?:off|no?|-)(\s*(#.*)?)$/im' => '\\1false\\2', |
|---|
| 36 |
)); |
|---|
| 37 |
|
|---|
| 38 |
try |
|---|
| 39 |
{ |
|---|
| 40 |
sfYaml::setSpecVersion('1.1'); |
|---|
| 41 |
$yaml11 = sfYaml::load($original); |
|---|
| 42 |
|
|---|
| 43 |
sfYaml::setSpecVersion('1.2'); |
|---|
| 44 |
$yaml12 = sfYaml::load($upgraded); |
|---|
| 45 |
} |
|---|
| 46 |
catch (Exception $e) |
|---|
| 47 |
{ |
|---|
| 48 |
|
|---|
| 49 |
$yaml11 = 'foo'; |
|---|
| 50 |
$yaml12 = 'bar'; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
if ($yaml11 == $yaml12) |
|---|
| 54 |
{ |
|---|
| 55 |
if ($original != $upgraded) |
|---|
| 56 |
{ |
|---|
| 57 |
$this->getFilesystem()->touch($file); |
|---|
| 58 |
file_put_contents($file, $upgraded); |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|
| 61 |
else |
|---|
| 62 |
{ |
|---|
| 63 |
$this->logSection('yaml', 'Unable to upgrade '.sfDebug::shortenFilePath($file), null, 'ERROR'); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
if ('1.1' != $specVersion) |
|---|
| 67 |
{ |
|---|
| 68 |
$specVersion = '1.1'; |
|---|
| 69 |
|
|---|
| 70 |
$class = sfClassManipulator::fromFile(sfConfig::get('sf_config_dir').'/ProjectConfiguration.class.php'); |
|---|
| 71 |
|
|---|
| 72 |
$original = $class->getCode(); |
|---|
| 73 |
$modified = $class->wrapMethod('setup', 'sfYaml::setSpecVersion(\'1.1\');'); |
|---|
| 74 |
|
|---|
| 75 |
if ($original != $modified && $this->askConfirmation(array( |
|---|
| 76 |
'Unable to convert YAML file:', |
|---|
| 77 |
sfDebug::shortenFilePath($file), |
|---|
| 78 |
'', |
|---|
| 79 |
'Would you like to force YAML to be parsed with the 1.1 specification? (Y/n)', |
|---|
| 80 |
), 'QUESTION_LARGE')) |
|---|
| 81 |
{ |
|---|
| 82 |
$this->logSection('yaml', 'Forcing YAML 1.1 spec'); |
|---|
| 83 |
|
|---|
| 84 |
$this->getFilesystem()->touch($class->getFile()); |
|---|
| 85 |
$class->save(); |
|---|
| 86 |
} |
|---|
| 87 |
else |
|---|
| 88 |
{ |
|---|
| 89 |
$this->logBlock(array('Unable to either upgrade YAML files or force 1.1 spec.', '(see UPGRADE_TO_1_3 file for more information)'), 'ERROR_LARGE'); |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
$success = false; |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
if ($success && '1.1' == $specVersion) |
|---|
| 98 |
{ |
|---|
| 99 |
$file = sfConfig::get('sf_config_dir').'/ProjectConfiguration.class.php'; |
|---|
| 100 |
$original = file_get_contents($file); |
|---|
| 101 |
$modified = preg_replace('/^\s*sfYaml::setSpecVersion\(\'1\.1\'\);\n/im', '', $original); |
|---|
| 102 |
|
|---|
| 103 |
if ($original != $modified) |
|---|
| 104 |
{ |
|---|
| 105 |
$this->logSection('yaml', 'Removing setting of YAML 1.1 spec'); |
|---|
| 106 |
|
|---|
| 107 |
$this->getFilesystem()->touch($file); |
|---|
| 108 |
file_put_contents($file, $modified); |
|---|
| 109 |
} |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|