00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Install_Model_Installer_Filesystem extends Mage_Install_Model_Installer_Abstract
00035 {
00036 const MODE_WRITE = 'write';
00037 const MODE_READ = 'read';
00038
00039 public function __construct()
00040 {
00041 }
00042
00043
00044
00045
00046
00047 public function install()
00048 {
00049 if (!$this->_checkFilesystem()) {
00050 throw new Exception();
00051 };
00052 return $this;
00053 }
00054
00055
00056
00057
00058
00059
00060 protected function _checkFilesystem()
00061 {
00062 $res = true;
00063 $config = Mage::getSingleton('install/config')->getPathForCheck();
00064
00065 if (isset($config['writeable'])) {
00066 foreach ($config['writeable'] as $item) {
00067 $recursive = isset($item['recursive']) ? $item['recursive'] : false;
00068 $existence = isset($item['existence']) ? $item['existence'] : false;
00069 $checkRes = $this->_checkPath($item['path'], $recursive, $existence, 'write');
00070 $res = $res && $checkRes;
00071 }
00072 }
00073 return $res;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 protected function _checkPath($path, $recursive, $existence, $mode)
00086 {
00087 $res = true;
00088 $fullPath = dirname(Mage::getRoot()).$path;
00089 if ($mode == self::MODE_WRITE) {
00090 $setError = false;
00091 if ($existence) {
00092 if ((is_dir($fullPath) && !is_dir_writeable($fullPath)) || !is_writable($fullPath)) {
00093 $setError = true;
00094 }
00095 }
00096 else {
00097 if (file_exists($fullPath) && !is_writable($fullPath)) {
00098 $setError = true;
00099 }
00100 }
00101
00102 if ($setError) {
00103 $this->_getInstaller()->getDataModel()->addError(
00104 Mage::helper('install')->__('Path "%s" must be writable', $fullPath)
00105 );
00106 $res = false;
00107 }
00108 }
00109
00110 if ($recursive && is_dir($fullPath)) {
00111 foreach (new DirectoryIterator($fullPath) as $file) {
00112 if (!$file->isDot() && $file->getFilename() != '.svn' && $file->getFilename() != '.htaccess') {
00113 $res = $res && $this->_checkPath($path.DS.$file->getFilename(), $recursive, $existence, $mode);
00114 }
00115 }
00116 }
00117 return $res;
00118 }
00119 }