| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfFormsUpgrade extends sfUpgrade |
|---|
| 20 |
{ |
|---|
| 21 |
public function upgrade() |
|---|
| 22 |
{ |
|---|
| 23 |
if (!file_exists($file = sfConfig::get('sf_lib_dir').'/form/BaseForm.class.php')) |
|---|
| 24 |
{ |
|---|
| 25 |
$properties = parse_ini_file(sfConfig::get('sf_config_dir').'/properties.ini', true); |
|---|
| 26 |
$tokens = array( |
|---|
| 27 |
'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', |
|---|
| 28 |
'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here' |
|---|
| 29 |
); |
|---|
| 30 |
|
|---|
| 31 |
$this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir').'/task/generator/skeleton/project/lib/form/BaseForm.class.php', $file); |
|---|
| 32 |
$this->getFilesystem()->replaceTokens(array($file), '##', '##', $tokens); |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
$finder = sfFinder::type('file')->name('*.php'); |
|---|
| 36 |
foreach ($finder->in($this->getProjectLibDirectories('/form')) as $file) |
|---|
| 37 |
{ |
|---|
| 38 |
$contents = file_get_contents($file); |
|---|
| 39 |
$changed = false; |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
$contents = preg_replace('/(\bextends\s+)sfForm\b/i', '\\1BaseForm', $contents, -1, $count); |
|---|
| 43 |
$changed = $count || $changed; |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
$contents = preg_replace('/\bnew\s+sfWidgetFormInput\b/i', '\\0Text', $contents, -1, $count); |
|---|
| 47 |
$changed = $count || $changed; |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
$contents = preg_replace('/public\s+function\s+processValues\s*\(\s*\$\w+(\s*=\s*null\s*)\)/ie', "str_replace('$1', '', '$0')", $contents, -1, $count); |
|---|
| 51 |
$changed = $count || $changed; |
|---|
| 52 |
|
|---|
| 53 |
if ($changed) |
|---|
| 54 |
{ |
|---|
| 55 |
$this->logSection('form', 'Migrating '.$file); |
|---|
| 56 |
file_put_contents($file, $contents); |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|