| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\App\Requirements\Handlers;
- use ThurData\Servers\KerioEmail\Core\App\Requirements\Handler;
- use ThurData\Servers\KerioEmail\Core\App\Requirements\HandlerInterface;
- use ThurData\Servers\KerioEmail\Core\App\Requirements\Instances\Files as FilesInstance;
- /**
- * Description of Files
- *
- * @autor ThurData <info@thrudata.ch>
- */
- class Files extends Handler implements HandlerInterface
- {
- use \ThurData\Servers\KerioEmail\Core\Traits\Lang;
-
- protected $fileList = [];
- public function __construct(array $fileList = [])
- {
- $this->fileList = $fileList;
-
- $this->handleRequirements();
- }
- public function handleRequirements()
- {
- foreach ($this->fileList as $record)
- {
- if (!$this->isValidPath($record[FilesInstance::PATH]))
- {
- continue;
- }
- $this->handleRequirement($record);
- }
- }
-
- public function isValidPath($path)
- {
- if (stripos($path, FilesInstance::WHMCS_PATH) === 0
- || stripos($path, FilesInstance::MODULE_PATH) === 0)
- {
- return true;
- }
-
- return false;
- }
-
- protected function handleRequirement($record)
- {
- $filePath = $this->getFullPath($record[FilesInstance::PATH]);
- switch ($record[FilesInstance::TYPE])
- {
- case FilesInstance::REMOVE:
- $this->removeFile($filePath);
- break;
- case FilesInstance::IS_WRITABLE:
- $this->checkIfWritable($filePath);
- break;
- }
-
- }
-
- public function getFullPath($recordPath = null)
- {
- if (stripos($recordPath, FilesInstance::WHMCS_PATH) === 0)
- {
- return str_replace(FilesInstance::WHMCS_PATH, \ThurData\Servers\KerioEmail\Core\ModuleConstants::getFullPathWhmcs(),
- str_replace('/', DIRECTORY_SEPARATOR, $recordPath));
- }
- if (stripos($recordPath, FilesInstance::MODULE_PATH) === 0)
- {
- return str_replace(FilesInstance::MODULE_PATH, \ThurData\Servers\KerioEmail\Core\ModuleConstants::getModuleRootDir(),
- str_replace('/', DIRECTORY_SEPARATOR, $recordPath));
- }
- return null;
- }
-
- protected function removeFile($filePath = null)
- {
- $fileValidator = new \ThurData\Servers\KerioEmail\Core\FileReader\PathValidator();
- if (!$fileValidator->pathExists($filePath))
- {
- return null;
- }
-
- unlink($filePath);
-
- if (!$fileValidator->pathExists($filePath))
- {
- return null;
- }
- $this->addUnfulfilledRequirement('In order for the module to work correctly, please remove the following file: :remove_file_requirement:',
- ['remove_file_requirement' => $filePath]);
- }
- protected function checkIfWritable($filePath = null)
- {
- $fileValidator = new \ThurData\Servers\KerioEmail\Core\FileReader\PathValidator();
- if ($fileValidator->isPathWritable($filePath))
- {
- return null;
- }
- $this->addUnfulfilledRequirement('In order for the module to work correctly, please set up permissions to the :writable_file_requirement: directory as writable.',
- ['writable_file_requirement' => $filePath]);
- }
- }
|