Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) 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
 * Fixes symfony directory permissions.
13
 *
14
 * @package    symfony
15
 * @subpackage task
16
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17
 * @version    SVN: $Id: sfProjectPermissionsTask.class.php 23922 2009-11-14 14:58:38Z fabien $
18
 */
19
class sfProjectPermissionsTask extends sfBaseTask
20
{
21
  protected
22
    $current = null,
23
    $failed  = array();
24
 
25
  /**
26
   * @see sfTask
27
   */
28
  protected function configure()
29
  {
30
    $this->namespace = 'project';
31
    $this->name = 'permissions';
32
    $this->briefDescription = 'Fixes symfony directory permissions';
33
 
34
    $this->detailedDescription = <<<EOF
35
The [project:permissions|INFO] task fixes directory permissions:
36
 
37
  [./symfony project:permissions|INFO]
38
EOF;
39
  }
40
 
41
  /**
42
   * @see sfTask
43
   */
44
  protected function execute($arguments = array(), $options = array())
45
  {
46
    if (file_exists(sfConfig::get('sf_upload_dir')))
47
    {
48
      $this->chmod(sfConfig::get('sf_upload_dir'), 0777);
49
    }
50
 
51
    $this->chmod(sfConfig::get('sf_cache_dir'), 0777);
52
    $this->chmod(sfConfig::get('sf_log_dir'), 0777);
53
    $this->chmod(sfConfig::get('sf_root_dir').'/symfony', 0777);
54
 
55
    $dirs = array(
56
      sfConfig::get('sf_cache_dir'),
57
      sfConfig::get('sf_log_dir'),
58
      sfConfig::get('sf_upload_dir'),
59
    );
60
 
61
    $dirFinder = sfFinder::type('dir');
62
    $fileFinder = sfFinder::type('file');
63
 
64
    foreach ($dirs as $dir)
65
    {
66
      $this->chmod($dirFinder->in($dir), 0777);
67
      $this->chmod($fileFinder->in($dir), 0666);
68
    }
69
 
70
    // note those files that failed
71
    if (count($this->failed))
72
    {
73
      $this->logBlock(array_merge(
74
        array('Permissions on the following file(s) could not be fixed:', ''),
75
        array_map(create_function('$f', 'return \' - \'.sfDebug::shortenFilePath($f);'), $this->failed)
76
      ), 'ERROR_LARGE');
77
    }
78
  }
79
 
80
  /**
81
   * Chmod and capture any failures.
82
   *
83
   * @param string  $file
84
   * @param integer $mode
85
   * @param integer $umask
86
   *
87
   * @see sfFilesystem
88
   */
89
  protected function chmod($file, $mode, $umask = 0000)
90
  {
91
    if (is_array($file))
92
    {
93
      foreach ($file as $f)
94
      {
95
        $this->chmod($f, $mode, $umask);
96
      }
97
    }
98
    else
99
    {
100
      set_error_handler(array($this, 'handleError'));
101
 
102
      $this->current = $file;
103
      @$this->getFilesystem()->chmod($file, $mode, $umask);
104
      $this->current = null;
105
 
106
      restore_error_handler();
107
    }
108
  }
109
 
110
  /**
111
   * Captures those chmod commands that fail.
112
   *
113
   * @see http://www.php.net/set_error_handler
114
   */
115
  public function handleError($no, $string, $file, $line, $context)
116
  {
117
    $this->failed[] = $this->current;
118
  }
119
}