Beispiel #1
0
 /**
  * doActionDelete
  *
  * @return void
  * @throws
  */
 protected function doActionDelete()
 {
     if (\Includes\Utils\FileManager::isExists($this->sqldumpFile) && !\Includes\Utils\FileManager::deleteFile($this->sqldumpFile)) {
         \XLite\Core\TopMessage::addError(static::t('Unable to delete file') . ' ' . $this->sqldumpFile);
     } else {
         \XLite\Core\TopMessage::addInfo('SQL file was deleted successfully');
     }
     $this->doRedirect();
 }
Beispiel #2
0
 /**
  * Process item
  *
  * @param mixed $item Item
  *
  * @return boolean
  */
 protected function processItem($item)
 {
     $result = false;
     $path = tempnam(LC_DIR_TMP, 'migrate_file');
     file_put_contents($path, $item->getBody());
     if (\Includes\Utils\FileManager::isExists($path)) {
         $localPath = $item->isURL() ? null : $item->getStoragePath();
         $result = $item->loadFromLocalFile($path, $item->getFileName() ?: basename($item->getPath()));
         if ($result && $localPath && \Includes\Utils\FileManager::isExists($localPath)) {
             \Includes\Utils\FileManager::deleteFile($localPath);
         }
         \Includes\Utils\FileManager::deleteFile($path);
     }
     if (!$result) {
         if (!isset($this->record['s3_error_count'])) {
             $this->record['s3_error_count'] = 0;
         }
         $this->record['s3_error_count']++;
         \XLite\Logger::getInstance()->log('Couldn\'t move image ' . $item->getPath() . ' (local file system to Amazon S3)', LOG_ERR);
     }
     return true;
 }
Beispiel #3
0
 /**
  * Update custom images
  *
  * @return void
  */
 protected function updateCustomImages()
 {
     $dir = \XLite\Module\XC\ThemeTweaker\Main::getThemeDir() . 'images' . LC_DS;
     if ($_FILES && $_FILES['new_images'] && $_FILES['new_images']['name']) {
         if (!\Includes\Utils\FileManager::isExists($dir)) {
             \Includes\Utils\FileManager::mkdirRecursive($dir);
         }
         if (\Includes\Utils\FileManager::isDirWriteable($dir)) {
             foreach ($_FILES['new_images']['name'] as $i => $data) {
                 \Includes\Utils\FileManager::moveUploadedFileByMultiple('new_images', $i, $dir);
             }
         } else {
             \XLite\Core\TopMessage::addError('The directory {{dir}} does not exist or is not writable.', array('dir' => $dir));
         }
     }
     $delete = \XLite\Core\Request::getInstance()->delete;
     if ($delete && is_array($delete)) {
         foreach ($delete as $file => $del) {
             if ($del) {
                 \Includes\Utils\FileManager::deleteFile($dir . $file);
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Populate model object properties by the passed data
  *
  * @param array $data Data to set
  *
  * @return void
  */
 protected function setModelProperties(array $data)
 {
     $options = $this->getOptions();
     $dir = LC_DIR_SKINS . \XLite\Core\Layout::PATH_COMMON . LC_DS;
     if ('CDev\\SimpleCMS' == $options[0]->category) {
         if ($_FILES && $_FILES['logo'] && $_FILES['logo']['name']) {
             $path = \Includes\Utils\FileManager::moveUploadedFile('logo', $dir);
             if ($path) {
                 if ($options[0]->value) {
                     \Includes\Utils\FileManager::deleteFile($dir . $options[0]->value);
                 }
                 $data['logo'] = basename($path);
             }
         } elseif (\XLite\Core\Request::getInstance()->useDefaultLogo) {
             $data['logo'] = '';
             if ($options[0]->value) {
                 \Includes\Utils\FileManager::deleteFile($dir . $options[0]->value);
             }
         } else {
             $data['logo'] = $options[0]->value;
         }
     }
     parent::setModelProperties($data);
 }
Beispiel #5
0
 /**
  * Set repository path
  *
  * @param string  $path            Path to set
  * @param boolean $preventCheck    Flag OPTIONAL
  * @param boolean $preventDeletion Flag OPTIONAL
  *
  * @return void
  */
 public function setRepositoryPath($path, $preventCheck = false, $preventDeletion = false)
 {
     if (!empty($path) && !$preventCheck) {
         $path = \Includes\Utils\FileManager::getRealPath($path);
         if (empty($path) || !\Includes\Utils\FileManager::isReadable($path)) {
             $path = null;
         }
     }
     if (!$preventDeletion && !empty($this->repositoryPath) && $path !== $this->repositoryPath) {
         if ($this->isDownloaded()) {
             \Includes\Utils\FileManager::deleteFile($this->repositoryPath);
         } elseif ($this->isUnpacked()) {
             \Includes\Utils\FileManager::deleteFile($this->getCurrentVersionHashesFilePath());
             \Includes\Utils\FileManager::unlinkRecursive($this->repositoryPath);
         }
     }
     $this->repositoryPath = $path;
 }
Beispiel #6
0
 /**
  * Renew parameters
  *
  * @return boolean
  */
 protected function renew()
 {
     $result = false;
     list($path, $isTempFile) = $this->getLocalPath();
     $result = $this->isFileExists($path, $isTempFile) && $this->renewByPath($path);
     if ($isTempFile || !$result && !$this->isURL($path)) {
         \Includes\Utils\FileManager::deleteFile($path);
     }
     return $result;
 }
Beispiel #7
0
 /**
  * Delete by prefix
  *
  * @param string $prefix Prefix
  *
  * @return array
  */
 public function deleteByPrefix($prefix)
 {
     $deleted = array();
     $prefix = $this->getNamespacedIdToDelete($prefix);
     $list = glob($this->path . LC_DS . $prefix);
     if ($list) {
         foreach ($list as $f) {
             if ($this->isKeyValid($f)) {
                 $id = substr(basename($f), 0, -4);
                 \Includes\Utils\FileManager::deleteFile($f);
                 $deleted[] = $id;
             }
         }
     }
     return $deleted;
 }
Beispiel #8
0
 /**
  * Delete all files
  *
  * @return void
  */
 public function deleteAllFiles()
 {
     $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->getOptions()->dir);
     if (!\Includes\Utils\FileManager::isExists($dir)) {
         \Includes\Utils\FileManager::mkdir($dir);
     }
     $list = glob($dir . LC_DS . '*');
     if ($list) {
         foreach ($list as $path) {
             if (is_file($path)) {
                 \Includes\Utils\FileManager::deleteFile($path);
             } else {
                 \Includes\Utils\FileManager::unlinkRecursive($path);
             }
         }
     }
 }
Beispiel #9
0
 /**
  * Remove file with active modules list
  *
  * @return void
  */
 public static function clearUnsafeModules()
 {
     \Includes\Utils\FileManager::deleteFile(static::getUnsafeModulesFilePath());
 }
Beispiel #10
0
 /**
  * Remove compiled template
  *
  * @param string $original Relative file path
  *
  * @return void
  */
 public function remove($original)
 {
     $compiled = $this->compileDir . substr($original, $this->rootDirLength) . '.php';
     \Includes\Utils\FileManager::deleteFile($compiled);
 }
Beispiel #11
0
 /**
  * Save
  *
  * @param string $code Code
  *
  * @return void
  */
 protected function saveCode($code)
 {
     if ("\r\n" != PHP_EOL) {
         $code = str_replace("\r\n", PHP_EOL, $code);
     }
     $code = str_replace(chr(194) . chr(160), ' ', $code);
     $file = $this->getFileName();
     \Includes\Utils\FileManager::write($file, $code);
     if (\Includes\Utils\FileManager::isFileWriteable($file)) {
         \XLite\Core\TopMessage::addInfo('Your custom file is successfully saved');
         \Includes\Utils\FileManager::deleteFile(str_replace('custom', 'custom.min', $file));
         \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('name' => $this->getBackupName(), 'value' => $code, 'category' => 'XC\\ThemeTweaker'));
         \XLite\Core\Config::updateInstance();
         $config = \XLite\Core\Config::getInstance()->Performance;
         if ($config->aggregate_css || $config->aggregate_js) {
             \Includes\Utils\FileManager::unlinkRecursive(LC_DIR_CACHE_RESOURCES);
             \XLite\Core\TopMessage::addInfo('Aggregation cache has been cleaned');
         }
     } else {
         \XLite\Core\TopMessage::addError('The file {{file}} does not exist or is not writable.', array('file' => $file));
     }
 }
Beispiel #12
0
 /**
  * Call "Get Artifact" request (i.e. download PDF file)
  * To get error message you need to call "getApiCallErrors" method (if return is false)
  *
  * @param boolean $flushChanges Flag - flush changes or not
  *
  * @return boolean
  */
 public function callApiGetArtifact($flushChanges = false)
 {
     $result = false;
     if ($this->isGetArtifactCallAllowed() && $this->getStorageClass()) {
         $data = \XLite\Module\XC\CanadaPost\Core\API::getInstance()->callGetArtifactRequest($this);
         $storageClass = $this->getStorageClass();
         if (isset($data->filePath) && !empty($data->filePath)) {
             // Save PDF document to storage
             $storage = $this->getStorage();
             if (!isset($storage)) {
                 $storage = new $storageClass();
                 $storage->setLink($this);
                 $this->setStorage($storage);
             }
             $storage->loadFromLocalFile($data->filePath);
             $storage->setMime($this->getMediaType());
             \Includes\Utils\FileManager::deleteFile($data->filePath);
             $result = true;
             if ($flushChanges) {
                 \XLite\Core\Database::getEM()->flush();
             }
         }
         if (isset($data->errors)) {
             $this->apiCallErrors = $data->errors;
         }
     }
     return $result;
 }
Beispiel #13
0
 /**
  * Clear log file
  *
  * @return boolean
  */
 public function clear()
 {
     return \Includes\Utils\FileManager::deleteFile($this->getLogFile());
 }
Beispiel #14
0
 /**
  * Remove entity
  *
  * @param \XLite\Model\AEntity $entity Entity
  *
  * @return boolean
  */
 protected function removeEntity(\XLite\Model\AEntity $entity)
 {
     $pathSkin = 'theme_tweaker/default';
     $localPath = $entity->getTemplate();
     $shortPath = substr($localPath, strpos($localPath, LC_DS, strlen($pathSkin . LC_DS)) + strlen(LC_DS));
     $fullPath = $this->getFullPathByShortPath($shortPath);
     \Includes\Utils\FileManager::deleteFile($fullPath);
     \XLite\Core\FlexyCompiler::getInstance()->remove($fullPath);
     parent::removeEntity($entity);
     return true;
 }
Beispiel #15
0
 /**
  * Import action
  *
  * @return void
  */
 protected function doActionImport()
 {
     foreach (\XLite\Logic\Import\Importer::getImportOptionsList() as $key) {
         \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('category' => 'Import', 'name' => $key, 'value' => isset(\XLite\Core\Request::getInstance()->options[$key]) ? \XLite\Core\Request::getInstance()->options[$key] : false));
     }
     \XLite\Core\Config::updateInstance();
     $dirTo = LC_DIR_VAR . \XLite\Logic\Import\Importer::getImportDir();
     if (!\Includes\Utils\FileManager::isExists($dirTo)) {
         \Includes\Utils\FileManager::mkdirRecursive($dirTo);
     }
     $filesToImport = array();
     if ($_FILES && isset($_FILES['files']) && $_FILES['files']['name'] && $_FILES['files']['name'][0] && \Includes\Utils\FileManager::isDirWriteable($dirTo)) {
         $list = glob($dirTo . LC_DS . '*');
         if ($list) {
             foreach ($list as $path) {
                 if (is_file($path)) {
                     \Includes\Utils\FileManager::deleteFile($path);
                 }
             }
         }
         $files = $_FILES['files'];
         foreach ($files['name'] as $key => $name) {
             $path = null;
             if ($name && UPLOAD_ERR_OK === $files['error'][$key]) {
                 $path = \Includes\Utils\FileManager::getUniquePath($dirTo, $name ?: $files['name'][$key]);
                 if (move_uploaded_file($files['tmp_name'][$key], $path)) {
                     if (\XLite\Core\Archive::getInstance()->isArchive($path) || 'csv' == substr(strrchr($path, '.'), 1)) {
                         $filesToImport[] = $path;
                     } else {
                         \XLite\Core\TopMessage::addError('The "{{file}}" is not CSV or archive', array('file' => $name));
                         \Includes\Utils\FileManager::deleteFile($path);
                     }
                 } else {
                     $path = null;
                 }
             }
             if (!$path) {
                 \XLite\Core\TopMessage::addError('The "{{file}}" file was not uploaded', array('file' => $name));
             }
         }
     }
     if ($filesToImport) {
         \XLite\Logic\Import\Importer::run(\XLite\Logic\Import\Importer::assembleImportOptions() + array('files' => $filesToImport));
     }
 }
Beispiel #16
0
 /**
  * Check and (if available) compress TAR arctive
  *
  * @param \PharData $phar  Archive to compress
  * @param string    &$name Archive file name
  *
  * @return \PharData
  */
 protected static function compress(\PharData $phar, &$name)
 {
     if (static::canCompress()) {
         \Includes\Utils\FileManager::deleteFile($name);
         if ($extension = static::getExtension()) {
             \Includes\Utils\FileManager::deleteFile($name .= '.' . $extension);
         }
         $phar->compress(self::COMPRESSION_TYPE);
     }
     return $phar;
 }
Beispiel #17
0
 /**
  * Remove DB schema
  *
  * @return void
  */
 public static function removeDBSchema()
 {
     static::$schema = null;
     \Includes\Utils\FileManager::deleteFile(static::getDBSchemaFilePath());
 }
Beispiel #18
0
 /**
  * Remove file with active modules list
  *
  * @return void
  */
 public static function removeFile()
 {
     \Includes\Utils\FileManager::deleteFile(static::getModulesFilePath());
 }
Beispiel #19
0
 /**
  * Removes any images that were parsed
  *
  * @return void
  */
 public function unlinkImages()
 {
     foreach ($this->images as $image) {
         \Includes\Utils\FileManager::deleteFile($image['path']);
     }
 }
Beispiel #20
0
 /**
  * Check - image hash is equal data from DB or not
  *
  * @return boolean
  */
 public function checkImageHash()
 {
     $result = true;
     if ($this->getHash()) {
         list($path, $isTempFile) = $this->getLocalPath();
         $hash = \Includes\Utils\FileManager::getHash($path);
         if ($isTempFile) {
             \Includes\Utils\FileManager::deleteFile($path);
         }
         $result = $this->getHash() === $hash;
     }
     return $result;
 }
Beispiel #21
0
 /**
  * Remove fixtures
  *
  * @return void
  */
 public static function removeFixtures()
 {
     static::$fixtures = null;
     \Includes\Utils\FileManager::deleteFile(static::getFixturesFilePath());
 }
Beispiel #22
0
 /**
  * Finalize write 
  * 
  * @return void
  */
 protected function finalizeWrite()
 {
     if ($this->emptyFile) {
         if ($this->fileIndex) {
             \Includes\Utils\FileManager::deleteFile($this->getSitemapPath());
         }
     } else {
         \Includes\Utils\FileManager::write($this->getSitemapPath(), $this->getFooter(), FILE_APPEND);
     }
 }
Beispiel #23
0
 /**
  * Additional preparations for images.
  * Upload them into specific directory
  *
  * @param string $optionValue Option value
  * @param string $imageType   Image type
  *
  * @return string
  */
 protected function prepareImageData($optionValue, $imageType)
 {
     $dir = static::getLogoFaviconDir();
     if ($_FILES && $_FILES[$imageType] && $_FILES[$imageType]['name']) {
         $path = null;
         $realName = preg_replace('/([^a-zA-Z0-9_\\-\\.]+)/', '_', $_FILES[$imageType]['name']);
         if ($this->isImage($_FILES[$imageType]['tmp_name'], $realName)) {
             if (!\Includes\Utils\FileManager::isDir($dir)) {
                 \Includes\Utils\FileManager::mkdirRecursive($dir);
             }
             if (\Includes\Utils\FileManager::isDir($dir)) {
                 // Remove file with same name as uploaded file in the destination directory
                 \Includes\Utils\FileManager::deleteFile($dir . LC_DS . ('favicon' === $imageType ? static::FAVICON : $realName));
                 // Move uploaded file to destination directory
                 $path = \Includes\Utils\FileManager::moveUploadedFile($imageType, $dir, 'favicon' === $imageType ? static::FAVICON : $realName);
                 if ($path) {
                     if ($optionValue && 'favicon' !== $imageType && basename($optionValue) != $realName) {
                         // Remove old image file
                         \Includes\Utils\FileManager::deleteFile($dir . basename($optionValue));
                     }
                     $optionValue = static::getLogoFaviconSubDir() . basename($path);
                 }
             }
             if (!isset($path)) {
                 $this->logoFaviconValidation = false;
                 \XLite\Core\TopMessage::addError('The "{{file}}" file was not uploaded', array('file' => $realName));
             }
         } else {
             $this->logoFaviconValidation = false;
             \XLite\Core\TopMessage::addError('The "{{file}}" file is not allowed image and was not uploaded. Allowed images are: {{extensions}}', array('file' => $realName, 'extensions' => implode(', ', $this->getImageExtensions())));
         }
     } elseif (\XLite\Core\Request::getInstance()->useDefaultImage[$imageType]) {
         if ($optionValue) {
             \Includes\Utils\FileManager::deleteFile($dir . basename($optionValue));
         }
         $optionValue = '';
     }
     return $optionValue;
 }
Beispiel #24
0
 /**
  * Main public method: rebuild classes cache
  *
  * @return void
  */
 public static function rebuildCache()
 {
     static::checkPermissions(LC_DIR_VAR);
     $stepStatus = false;
     foreach (static::$steps as $step) {
         $stepStatus = static::runStepConditionally($step);
         if ($stepStatus && static::isDoOneStepOnly()) {
             // Break after first performed step if isDoOneStepOnly() returned true
             break;
         }
     }
     if (!$stepStatus) {
         // Clear classes cache
         \Includes\Utils\FileManager::deleteFile(static::getClassesHashPath());
     }
 }
Beispiel #25
0
 /**
  * Parse PHP files and return plain array with the class descriptors
  *
  * @return array
  */
 protected static function getClassesTreeIndex()
 {
     $index = array();
     // Iterate over all directories with PHP class files
     foreach (static::getClassFileIterator()->getIterator() as $path => $data) {
         // Use PHP Tokenizer to search class declaration
         if (($class = \Includes\Decorator\Utils\Tokenizer::getFullClassName($path)) && \Includes\Utils\Operator::checkIfLCClass($class)) {
             // File contains a class declaration: create node (descriptor)
             $node = new \Includes\Decorator\DataStructure\Graph\Classes($class);
             // Check parent class (so called optional dependencies for modules)
             $dependencies = $node->getTag('lc_dependencies', true);
             if (empty($dependencies) || \Includes\Utils\ModulesManager::areActiveModules($dependencies)) {
                 // Node is valid: add to the index
                 $index[$class] = $node;
             } else {
                 // The unused class file must be removed from the cache file structure
                 \Includes\Utils\FileManager::deleteFile($node->getFile());
             }
         }
     }
     return $index;
 }
Beispiel #26
0
 /**
  * Load from request
  *
  * @param string $key Key in $_FILES service array
  *
  * @return boolean
  */
 public function loadFromRequest($key)
 {
     if (!$this->s3Forbid && $this->getS3()) {
         $result = false;
         $path = \Includes\Utils\FileManager::moveUploadedFile($key, LC_DIR_TMP);
         if ($path) {
             $result = $this->loadFromLocalFile($path, $_FILES[$key]['name']);
             \Includes\Utils\FileManager::deleteFile($path);
         } else {
             \XLite\Logger::getInstance()->log('The file was not loaded', LOG_ERR);
         }
     } else {
         $result = parent::loadFromRequest($key);
     }
     return $result;
 }