Development

/branches/1.1/lib/task/project/upgrade1.1/sfFlashUpgrade.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/task/project/upgrade1.1/sfFlashUpgrade.class.php

Revision 7397, 2.3 kB (checked in by fabien, 7 years ago)

added sfTask::log() and sfTask::logSection() shortcuts

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 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  * Upgrade flash.
13  *
14  * @package    symfony
15  * @subpackage task
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfFlashUpgrade extends sfUpgrade
20 {
21   public function upgrade()
22   {
23     $this->upgradeActions();
24     $this->upgradeTemplates();
25     $this->upgradeFilters();
26   }
27
28   protected function upgradeActions()
29   {
30     $phpFinder = $this->getFinder('file')->prune('model')->name('*.php');
31     foreach ($phpFinder->in($dirs = $this->getProjectClassDirectories()) as $file)
32     {
33       $content = file_get_contents($file);
34       $content = str_replace(
35         array('$this->setFlash', '$this->getFlash', '$this->hasFlash'),
36         array('$this->getUser()->setFlash', '$this->getUser()->getFlash', '$this->getUser()->hasFlash'),
37         $content, $count
38       );
39       if ($count)
40       {
41         $this->logSection('flash', sprintf('Migrating %s', $file));
42         file_put_contents($file, $content);
43       }
44     }
45   }
46
47   protected function upgradeTemplates()
48   {
49     $phpFinder = $this->getFinder('file')->name('*.php');
50     foreach ($phpFinder->in($this->getProjectTemplateDirectories()) as $file)
51     {
52       $content = file_get_contents($file);
53       $content = str_replace(
54         array('$sf_flash->set', '$sf_flash->get', '$sf_flash->has'),
55         array('$sf_user->setFlash', '$sf_user->getFlash', '$sf_user->hasFlash'),
56         $content, $count
57       );
58       if ($count)
59       {
60         $this->logSection('flash', sprintf('Migrating %s', $file));
61         file_put_contents($file, $content);
62       }
63     }
64   }
65
66   protected function upgradeFilters()
67   {
68     $filtersFinder = $this->getFinder('file')->name('filters.yml');
69     foreach ($filtersFinder->in($this->getProjectConfigDirectories()) as $file)
70     {
71       $content = file_get_contents($file);
72       $content = preg_replace("#flash\:\s+~\s*\n#s", '', $content, -1, $count);
73       if ($count)
74       {
75         $this->logSection('flash', sprintf('Migrating %s', $file));
76         file_put_contents($file, $content);
77       }
78     }
79   }
80 }
81
Note: See TracBrowser for help on using the browser.