Ejemplo n.º 1
0
 private function doClean(DirItem $srcDi)
 {
     foreach (DirManager::autogen()->getSubDirNames('images') as $dim) {
         $cacheKey = md5("[{$srcDi}]:[{$dim}]");
         $this->CAHCE->remove($cacheKey);
         DirManager::autogen()->getHashedDirItem("images/{$dim}", $cacheKey, $cacheKey, SYSTEM_IMG_TYPE)->remove();
     }
 }
Ejemplo n.º 2
0
 public function clean($group = null)
 {
     $this->LOGGER->info($group ? "Очистка кеша по группе [{$group}]" : 'Полная очистка кеша');
     $this->CACHELITE->clean($group);
     if ($group) {
         //Эту группу больше не нужно валидировать
         $this->TREE->setGroupValidated($group);
         //Очистим ключи локального хранилища
         $keys = $this->CACHE->keys();
         $removed = array();
         $prefix = $this->localCacheGroup($group);
         foreach ($keys as $key) {
             if (starts_with($key, $prefix)) {
                 $removed[] = $key;
                 $this->CACHE->remove($key);
             }
         }
         if ($removed) {
             $this->LOGGER->info('В локальном кеше были удалены следующие ключи: {}.', concat($removed));
         }
     } else {
         $this->CACHE->clear();
         $this->TREE->setAllValidated('Полная очистка кеша');
     }
 }
Ejemplo n.º 3
0
 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;
 }