| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfPropelUpgrade extends sfUpgrade |
|---|
| 20 |
{ |
|---|
| 21 |
static protected |
|---|
| 22 |
$inserts = array( |
|---|
| 23 |
'propel.behavior.default' => 'symfony,symfony_i18n', |
|---|
| 24 |
'propel.behavior.symfony.class' => 'plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorSymfony', |
|---|
| 25 |
'propel.behavior.symfony_i18n.class' => 'plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorI18n', |
|---|
| 26 |
'propel.behavior.symfony_i18n_translation.class' => 'plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorI18nTranslation', |
|---|
| 27 |
'propel.behavior.symfony_behaviors.class' => 'plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorSymfonyBehaviors', |
|---|
| 28 |
'propel.behavior.symfony_timestampable.class' => 'plugins.sfPropelPlugin.lib.behavior.SfPropelBehaviorTimestampable', |
|---|
| 29 |
), |
|---|
| 30 |
$removes = array( |
|---|
| 31 |
'propel.builder.peer.class' => 'plugins.sfPropelPlugin.lib.builder.SfPeerBuilder', |
|---|
| 32 |
'propel.builder.object.class' => 'plugins.sfPropelPlugin.lib.builder.SfObjectBuilder', |
|---|
| 33 |
'propel.builder.objectstub.class' => 'plugins.sfPropelPlugin.lib.builder.SfExtensionObjectBuilder', |
|---|
| 34 |
'propel.builder.peerstub.class' => 'plugins.sfPropelPlugin.lib.builder.SfExtensionPeerBuilder', |
|---|
| 35 |
'propel.builder.objectmultiextend.class' => 'plugins.sfPropelPlugin.lib.builder.SfMultiExtendObjectBuilder', |
|---|
| 36 |
'propel.builder.mapbuilder.class' => 'plugins.sfPropelPlugin.lib.builder.SfMapBuilderBuilder', |
|---|
| 37 |
'propel.builder.nestedset.class' => 'plugins.sfPropelPlugin.lib.builder.SfNestedSetBuilder', |
|---|
| 38 |
'propel.builder.nestedsetpeer.class' => 'plugins.sfPropelPlugin.lib.builder.SfNestedSetPeerBuilder', |
|---|
| 39 |
); |
|---|
| 40 |
|
|---|
| 41 |
protected |
|---|
| 42 |
$properties = null; |
|---|
| 43 |
|
|---|
| 44 |
public function upgrade() |
|---|
| 45 |
{ |
|---|
| 46 |
if (!in_array('sfPropelPlugin', $this->configuration->getPlugins())) |
|---|
| 47 |
{ |
|---|
| 48 |
if (file_exists($file = sfConfig::get('sf_config_dir').'/propel.ini')) |
|---|
| 49 |
{ |
|---|
| 50 |
$this->getFilesystem()->remove($file); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
return; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
if ( |
|---|
| 57 |
file_exists($old = sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php') |
|---|
| 58 |
&& |
|---|
| 59 |
!file_exists($new = sfConfig::get('sf_lib_dir').'/filter/BaseFormFilterPropel.class.php') |
|---|
| 60 |
) |
|---|
| 61 |
{ |
|---|
| 62 |
$this->getFilesystem()->rename($old, $new); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
if (file_exists($file = sfConfig::get('sf_config_dir').'/propel.ini')) |
|---|
| 66 |
{ |
|---|
| 67 |
|
|---|
| 68 |
sfPhing::startup(); |
|---|
| 69 |
$this->properties = new Properties(); |
|---|
| 70 |
$this->properties->load(new PhingFile($file)); |
|---|
| 71 |
|
|---|
| 72 |
$modified = $original = file_get_contents($file); |
|---|
| 73 |
$modified = $this->upgradePropelIni($modified, self::$removes, false); |
|---|
| 74 |
$modified = $this->upgradePropelIni($modified, self::$inserts, true); |
|---|
| 75 |
|
|---|
| 76 |
if ($original != $modified) |
|---|
| 77 |
{ |
|---|
| 78 |
$this->logSection('propel', 'Upgrading '.sfDebug::shortenFilePath($file)); |
|---|
| 79 |
file_put_contents($file, $modified); |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
protected function upgradePropelIni($contents, $directives, $insert = false) |
|---|
| 85 |
{ |
|---|
| 86 |
static $header = false; |
|---|
| 87 |
|
|---|
| 88 |
$failures = array(); |
|---|
| 89 |
|
|---|
| 90 |
foreach ($directives as $key => $value) |
|---|
| 91 |
{ |
|---|
| 92 |
$current = $this->properties->get($key); |
|---|
| 93 |
|
|---|
| 94 |
if (null === $current) |
|---|
| 95 |
{ |
|---|
| 96 |
if ($insert) |
|---|
| 97 |
{ |
|---|
| 98 |
if (!$header) |
|---|
| 99 |
{ |
|---|
| 100 |
$contents = rtrim($contents).PHP_EOL.PHP_EOL.'; symfony 1.3 upgrade ('.date('Y/m/d H:i:s').')'.PHP_EOL; |
|---|
| 101 |
$header = true; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
$contents = $contents.$key.' = '.$value.PHP_EOL; |
|---|
| 106 |
$this->properties->setProperty($key, $value); |
|---|
| 107 |
} |
|---|
| 108 |
} |
|---|
| 109 |
else if ($value == $current) |
|---|
| 110 |
{ |
|---|
| 111 |
if (!$insert) |
|---|
| 112 |
{ |
|---|
| 113 |
|
|---|
| 114 |
$contents = preg_replace('/^'.preg_quote($key).'[\s=]/m', ';\\0', $contents); |
|---|
| 115 |
$this->properties->setProperty($key, null); |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
else |
|---|
| 119 |
{ |
|---|
| 120 |
$failures[] = $key; |
|---|
| 121 |
} |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
if ($failures) |
|---|
| 125 |
{ |
|---|
| 126 |
$this->logBlock(array_merge( |
|---|
| 127 |
array(sprintf('Please %s or upgrade the following propel.ini directive(s):', $insert ? 'insert' : 'remove'), ''), |
|---|
| 128 |
array_map(create_function('$v', 'return \' - \'.$v;'), $failures) |
|---|
| 129 |
), 'ERROR_LARGE'); |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
return $contents; |
|---|
| 133 |
} |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|