| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfTasksUpgrade extends sfUpgrade |
|---|
| 20 |
{ |
|---|
| 21 |
public function upgrade() |
|---|
| 22 |
{ |
|---|
| 23 |
$finder = sfFinder::type('file')->name('*.php'); |
|---|
| 24 |
foreach ($finder->in($this->getProjectLibDirectories('/task')) as $file) |
|---|
| 25 |
{ |
|---|
| 26 |
$contents = file_get_contents($file); |
|---|
| 27 |
$changed = false; |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
if (preg_match_all('/\bnew\b\s+\bsf(Doctrine|Propel)(Load|Dump)DataTask\b/i', $contents, $matches, PREG_OFFSET_CAPTURE)) |
|---|
| 31 |
{ |
|---|
| 32 |
foreach ($matches[0] as $match) |
|---|
| 33 |
{ |
|---|
| 34 |
list($search, $offset) = $match; |
|---|
| 35 |
$replace = str_ireplace(array('LoadData', 'DumpData'), array('DataLoad', 'DataDump'), $search); |
|---|
| 36 |
|
|---|
| 37 |
$contents = substr($contents, 0, $offset).$replace.substr($contents, $offset + strlen($search)); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
$changed = true; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
if (preg_match_all('/\bnew\b\s+\bsfConfigureDatabaseTask\b/i', $contents, $matches, PREG_OFFSET_CAPTURE)) |
|---|
| 45 |
{ |
|---|
| 46 |
$newTask = sprintf('sf%sConfigureDatabaseTask', ucfirst(sfConfig::get('sf_orm'))); |
|---|
| 47 |
foreach ($matches[0] as $match) |
|---|
| 48 |
{ |
|---|
| 49 |
list($search, $offset) = $match; |
|---|
| 50 |
$replace = str_ireplace('sfConfigureDatabaseTask', $newTask, $search); |
|---|
| 51 |
|
|---|
| 52 |
$contents = substr($contents, 0, $offset).$replace.substr($contents, $offset + strlen($search)); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
$changed = true; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
if ($changed) |
|---|
| 59 |
{ |
|---|
| 60 |
$this->logSection('task', 'Migrating '.$file); |
|---|
| 61 |
file_put_contents($file, $contents); |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
} |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|