sfPropel13Upgrade.class.php 2.8 KB

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