예제 #1
0
파일: mhd.php 프로젝트: janci/MHDv2
 /**
  * In destructor saving getting data to cache - file
  */
 public function __destruct()
 {
     if (!is_null($this->cache)) {
         $this->cache->stops = $this->stops;
         $this->cache->departures = $this->departures;
         $this->cache->spoje = $this->spoje;
         $this->cache->form_url = $this->form_url;
         $this->cache->categories = $this->categories;
         $this->cache->save();
     }
 }
예제 #2
0
    /**
     * Updates file in cashe. Even if it already in it.
     * @param $fileitentifier
     */
    public static function updateFileInCache($fileitentifier) {
        $path = FileModification::createDirectory('filecache');
        $path = FileModification::createDirectory('filecache/'.Yii::app()->user->clientID);

        if (is_file($fileitentifier)) {
            //if this if image from filesystem

            //convert to pdf
            $result_file_array = FileModification::PdfByFilePath($fileitentifier);
            $filepath = $result_file_array['filepath'];
            $filename = $result_file_array['filename'];

            $path_to_base = $filepath;
            $fileId = sha1_file($filepath).sha1($filepath);

        } else {
            //if this is image from database
                $image = Images::model()->findByAttributes(array(
                    'Document_ID' => intval($fileitentifier)
                ));

                if($image) {
                    $mime = explode('/', $image->Mime_Type);
                    $temp_file_path = $path . '/' . $image->File_Name;
                    $infile = stripslashes($image->Img);
                    file_put_contents($temp_file_path, $infile);

                    $fileId = intval($fileitentifier);
                    $path_to_base = $temp_file_path;
                }
        }


        FileCache::deleteFromCacheById($fileitentifier);
        FileCache::deleteFromCacheById($fileId);

        $fileCash = new FileCache();

            $fileCash->file_id = $fileId;
            $fileCash->path = $path_to_base;
            $fileCash->client_id = Yii::app()->user->clientID;
            $fileCash->user_id = Yii::app()->user->userID;
            $fileCash->Created = time();
            $fileCash->save();

            $result_id = $fileCash->file_id;

        return $result_id;
    }
예제 #3
0
 /**
  * @param string $key
  * @param mixed $value
  * @return void
  * @throws FileOpenFailedException
  * @throws FileWriteFailedException
  */
 public function save($key, $value)
 {
     $this->memoryCache->save($key, $value);
     $this->fileCache->save($key, $value);
 }
예제 #4
0
 /**
  * This initialize those include path.
  * 
  */
 public static function initialize()
 {
     //this is set for FileCache usage
     $root = PathService::getRootDir();
     $configFile = $root . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "config.ini";
     if (file_exists($configFile)) {
         set_include_path(get_include_path() . PATH_SEPARATOR . "app" . DIRECTORY_SEPARATOR . "library" . DIRECTORY_SEPARATOR . "cache");
         if (!is_null(FileCache::get(self::FILECACHE))) {
             set_include_path(FileCache::get(self::FILECACHE));
             return;
         }
     }
     set_include_path(get_include_path() . PATH_SEPARATOR . "core");
     set_include_path(get_include_path() . PATH_SEPARATOR . "config");
     set_include_path(get_include_path() . PATH_SEPARATOR . "app");
     set_include_path(get_include_path() . PATH_SEPARATOR . "app" . DIRECTORY_SEPARATOR . "library");
     set_include_path(get_include_path() . PATH_SEPARATOR . "project");
     set_include_path(get_include_path() . PATH_SEPARATOR . "project" . DIRECTORY_SEPARATOR . "share");
     set_include_path(get_include_path() . PATH_SEPARATOR . "project" . DIRECTORY_SEPARATOR . "modules");
     set_include_path(get_include_path() . PATH_SEPARATOR . "plugin");
     //set module paths
     $modulePath = $root . DIRECTORY_SEPARATOR . "project" . DIRECTORY_SEPARATOR . "modules";
     $moduleFolders = Initializer::getDirectory($modulePath, TRUE);
     foreach ($moduleFolders as $i => $mfolder) {
         $fd = trim($mfolder);
         $rp = trim($modulePath) . DIRECTORY_SEPARATOR;
         $f = "modules" . DIRECTORY_SEPARATOR . str_replace($rp, "", $fd);
         set_include_path(get_include_path() . PATH_SEPARATOR . $f);
     }
     /**
      * include folders under project, library, plug-in
      *  
      */
     $plugIn = $root . DIRECTORY_SEPARATOR . "plugin";
     $coreLib = $root . DIRECTORY_SEPARATOR . "app" . DIRECTORY_SEPARATOR . "library";
     $project = $root . DIRECTORY_SEPARATOR . "project";
     $plugInFolders = Initializer::getDirectory($plugIn, TRUE);
     foreach ($plugInFolders as $i => $folder1) {
         $fd = trim($folder1);
         $rp = trim($plugIn) . DIRECTORY_SEPARATOR;
         $f = "plugin" . DIRECTORY_SEPARATOR . str_replace($rp, "", $fd);
         set_include_path(get_include_path() . PATH_SEPARATOR . $f);
     }
     $coreLibFolders = Initializer::getDirectory($coreLib, TRUE);
     foreach ($coreLibFolders as $i => $folder1) {
         $fd = trim($folder1);
         $rp = trim($coreLib) . DIRECTORY_SEPARATOR;
         $f = "app" . DIRECTORY_SEPARATOR . "library" . DIRECTORY_SEPARATOR . str_replace($rp, "", $fd);
         set_include_path(get_include_path() . PATH_SEPARATOR . $f);
     }
     $projectFolders = Initializer::getDirectory($project, TRUE);
     foreach ($projectFolders as $i => $folder1) {
         $fd = trim($folder1);
         $rp = trim($project) . DIRECTORY_SEPARATOR;
         $f = "project" . DIRECTORY_SEPARATOR . str_replace($rp, "", $fd);
         set_include_path(get_include_path() . PATH_SEPARATOR . $f);
     }
     if (file_exists($configFile)) {
         FileCache::save(self::FILECACHE, get_include_path());
     }
 }