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

Debug toolbar