Development

/branches/1.2/lib/task/project/upgrade1.2/sfPropel13Upgrade.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/task/project/upgrade1.2/sfPropel13Upgrade.class.php

Revision 12804, 2.8 kB (checked in by fabien, 5 years ago)

[1.2] added nested sets builders inthe upgrade task (closes #4620)

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Date Author Revision"
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2008 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * Upgrades propel.ini, databases.yml, and attempts to update object model for
13  * changes between Propel 1.2 and Propel 1.3.
14  *
15  * @package    symfony
16  * @subpackage task
17  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
18  * @version    SVN: $Id: sfPropelUpgrade.class.php 8369 2008-04-08 23:39:27Z dwhittle $
19  */
20 class sfPropel13Upgrade extends sfUpgrade
21 {
22   public function upgrade()
23   {
24     $file = sfConfig::get('sf_config_dir').'/propel.ini';
25     if(is_readable($file))
26     {
27       // builders paths
28       $content = file_get_contents($file);
29       $content = str_replace('addon.propel.builder.', 'plugins.sfPropelPlugin.lib.propel.builder.', $content, $count);
30
31       if ($count)
32       {
33         $this->logSection('propel', sprintf('Migrating %s', $file));
34         file_put_contents($file, $content);
35       }
36
37       // nested sets paths
38       if (false === strpos($content, 'nestedsetpeer'))
39       {
40         $content .= <<<EOF
41 propel.builder.nestedset.class         = plugins.sfPropelPlugin.lib.builder.SfNestedSetBuilder
42 propel.builder.nestedsetpeer.class     = plugins.sfPropelPlugin.lib.builder.SfNestedSetPeerBuilder
43 EOF;
44         $this->logSection('propel', sprintf('Migrating %s', $file));
45         file_put_contents($file, $content);
46       }
47
48       // add default date and time format
49       $content = file_get_contents($file);
50       if (false === strpos($content, 'propel.defaultDateFormat'))
51       {
52         $content .= <<<EOF
53
54 propel.defaultTimeStampFormat = Y-m-d H:i:s
55 propel.defaultTimeFormat = H:i:s
56 propel.defaultDateFormat = Y-m-d
57
58 EOF;
59         $this->logSection('propel', sprintf('Migrating %s', $file));
60         file_put_contents($file, $content);
61       }
62     }
63
64     $models = sfFinder::type('file')->name('*.php')->maxdepth(0)->in(sfConfig::get('sf_lib_dir').'/model');
65     foreach ($models as $model)
66     {
67       if(is_readable($model))
68       {
69         $content = file_get_contents($model);
70         $content = str_replace(array('public function save($con = null)', 'public function delete($con = null)', 'SQLException', '->begin();', '->rollback();', '->prepareStatement(', '->executeQuery();'),
71                                array('public function save(PropelPDO $con = null)', 'public function delete(PropelPDO $con = null)', 'PDOException', '->beginTransaction();', '->rollBack();', '->prepare(', '->execute();'),
72                                $content, $count);
73
74         if ($count)
75         {
76           $this->logSection('propel', sprintf('Migrating %s', $model));
77           file_put_contents($model, $content);
78         }
79       }
80
81     }
82   }
83 }
84
Note: See TracBrowser for help on using the browser.