public function appendFile(DirItem $file, $ensure = true) { $contents = trim($file->getFileContents($ensure)); if ($contents) { $contents = remove_utf8_bom($contents); $this->appendMlComment("+ FILE [{$file->getName()}]"); $this->di->writeLineToFile($contents); } unset($contents); }
private function saveCommonExcluded($class) { $pathes = $this->loadCommonExcluded(true); if (in_array($class, $pathes)) { //Класс уже отмечен, как исключённый return; //--- } $pathes[] = $class; $this->COMMON_EXCLUDED = $pathes; $this->COMMON_EXCLUDED_DI->saveArrayToFile($pathes); $this->COMMON_EXCLUDED_DI->getSibling($this->COMMON_EXCLUDED_DI->getName() . '_arr')->putToFile(print_r($pathes, true)); }
private function uploadFileImpl(DirItem $source, FILEAdapter $file = null, $userId = null, array $params = array()) { $userId = $this->checkUserId($userId); $this->LOGGER->info("Processing file upload for user [{$userId}], source {$source}."); $aa = ArrayAdapter::inst($params); $uploaded = $file ? $source : null; $originalName = $file ? $file->getOriginalName() : $source->getName(); $dbMsg = null; try { $this->LOGGER->info('Calling onBeforeSave...'); $dbMsg = $this->onBeforeSave($source, $userId, $aa); $this->LOGGER->info("\tDone!"); } catch (Exception $ex) { $this->LOGGER->info('Error occurred in onBeforeSave method: ' . $ex->getMessage()); $this->LOGGER->info('Source file will be deleted ? {}.', var_export(!!$uploaded, true)); if ($uploaded) { $uploaded->remove(); } throw $ex; } if ($uploaded) { //Это уже и так загруженный файл $this->LOGGER->info('Source file is uploaded file'); } else { $this->LOGGER->info('Move source file to uploads dir'); $uploaded = $this->makeTmpDirItem(); $source->copyTo($uploaded); } if ($this->LOGGER->isEnabled()) { $this->LOGGER->info("\tUploaded file: {$uploaded}"); $this->LOGGER->info("\tOriginal name: [{$originalName}]"); $this->LOGGER->info("\tMime: [{$uploaded->getMime()}]"); $this->LOGGER->info("\tParams: " . array_to_string($params, false)); } $uploadId = null; if ($this->isStoreToDb()) { $this->LOGGER->info("Saving upload file into database. DbMsg: '{$dbMsg}'."); try { $uploadId = UploadsBean::inst()->saveFileUpload($this->DBTYPE, $uploaded->getAbsPath(), $originalName, $uploaded->getMime(), $userId, $dbMsg); //Почистим кеш, вдруг мы запрашивали информацию по данному файлу $this->CACHE->remove($uploadId); $this->LOGGER->info("\tFile successfully saved, uploadId = {$uploadId}."); } catch (Exception $ex) { $this->LOGGER->info('Error occured while saving file to DB: ' . $ex->getMessage()); $this->LOGGER->info('Deleting upload file...'); $uploaded->remove(); $uploaded = null; throw $ex; } $uploaded->setData('id', $uploadId); } try { $this->LOGGER->info('Calling onAfterSave...'); $this->onAfterSave($uploaded, $userId, $aa); $this->LOGGER->info("\tDone!"); } catch (Exception $ex) { $this->LOGGER->info('Error occured in onAfterSave method: ' . $ex->getMessage()); if (is_inumeric($uploadId)) { $this->LOGGER->info('Deleting db record...'); UploadsBean::inst()->clearFileUpload($uploadId); $uploadId = null; } $this->LOGGER->info('Deleting upload file...'); $uploaded->remove(); $uploaded = null; throw $ex; } /* * Если класс работает автономно и не работает с базой, то файл нужно удалить. */ if ($this->isAutonomous() && !$this->isStoreToDb()) { $this->LOGGER->info('Class is auto clean, deleting uploaded file...'); $uploaded->remove(); $uploaded = null; } $this->LOGGER->info(''); return $uploaded; }
private function byNameCs(DirItem $i1, DirItem $i2) { return strcmp($i1->getName(), $i2->getName()); }