| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfSingletonUpgrade extends sfUpgrade |
|---|
| 20 |
{ |
|---|
| 21 |
public function upgrade() |
|---|
| 22 |
{ |
|---|
| 23 |
$this->upgradeFactoryCalls(); |
|---|
| 24 |
$this->upgradeFactoryConfiguration(); |
|---|
| 25 |
$this->upgradeSettingConfiguration(); |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
public function upgradeFactoryCalls() |
|---|
| 29 |
{ |
|---|
| 30 |
$phpFinder = $this->getFinder('file')->name('*.php'); |
|---|
| 31 |
foreach ($phpFinder->in($this->getProjectClassDirectories()) as $file) |
|---|
| 32 |
{ |
|---|
| 33 |
$content = file_get_contents($file); |
|---|
| 34 |
$content = str_replace( |
|---|
| 35 |
array('sfI18N::getInstance()', 'sfRouting::getInstance()', 'sfLogger::getInstance()'), |
|---|
| 36 |
array('sfContext::getInstance()->getI18N()', 'sfContext::getInstance()->getRouting()', 'sfContext::getInstance()->getLogger()'), |
|---|
| 37 |
$content, $count |
|---|
| 38 |
); |
|---|
| 39 |
|
|---|
| 40 |
if ($count) |
|---|
| 41 |
{ |
|---|
| 42 |
$this->logSection('singleton', sprintf('Migrating %s', $file)); |
|---|
| 43 |
file_put_contents($file, $content); |
|---|
| 44 |
} |
|---|
| 45 |
} |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
public function upgradeFactoryConfiguration() |
|---|
| 49 |
{ |
|---|
| 50 |
$phpFinder = $this->getFinder('file')->name('factories.yml'); |
|---|
| 51 |
foreach ($phpFinder->in($this->getProjectConfigDirectories()) as $file) |
|---|
| 52 |
{ |
|---|
| 53 |
$content = file_get_contents($file); |
|---|
| 54 |
if (false !== strpos($content, 'sfNoLogger')) |
|---|
| 55 |
{ |
|---|
| 56 |
continue; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
$content = |
|---|
| 60 |
<<<EOF |
|---|
| 61 |
prod: |
|---|
| 62 |
logger: |
|---|
| 63 |
class: sfNoLogger |
|---|
| 64 |
param: |
|---|
| 65 |
level: err |
|---|
| 66 |
loggers: ~ |
|---|
| 67 |
|
|---|
| 68 |
EOF |
|---|
| 69 |
.$content; |
|---|
| 70 |
|
|---|
| 71 |
$this->logSection('factories.yml', sprintf('Migrating %s', $file)); |
|---|
| 72 |
file_put_contents($file, $content); |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
public function upgradeSettingConfiguration() |
|---|
| 77 |
{ |
|---|
| 78 |
$phpFinder = $this->getFinder('file')->name('settings.yml'); |
|---|
| 79 |
foreach ($phpFinder->in($this->getProjectConfigDirectories()) as $file) |
|---|
| 80 |
{ |
|---|
| 81 |
$content = file_get_contents($file); |
|---|
| 82 |
if (false !== strpos($content, 'logging_enabled')) |
|---|
| 83 |
{ |
|---|
| 84 |
continue; |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
$content = preg_replace('/(prod\:\s+\.settings\:)/s', "$1\n logging_enabled: off", $content); |
|---|
| 88 |
|
|---|
| 89 |
$this->logSection('settings.yml', sprintf('Migrating %s', $file)); |
|---|
| 90 |
file_put_contents($file, $content); |
|---|
| 91 |
} |
|---|
| 92 |
} |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|