getContext() public static method

public static getContext ( ) : null | resource
return null | resource
Example #1
0
 /**
  * @return mixed|void
  * @throws DAV\Exception\Forbidden
  */
 public function get()
 {
     if ($this->asset->isAllowed("view")) {
         return fopen($this->asset->getFileSystemPath(), "r", false, FileHelper::getContext());
     } else {
         throw new DAV\Exception\Forbidden();
     }
 }
Example #2
0
 /**
  * Object
  *
  * @return mixed
  */
 public function loadData()
 {
     $data = null;
     $zipped = false;
     // check both the legacy file path and the new structure
     foreach ([$this->getFilePath(), $this->getLegacyFilePath()] as $path) {
         if (file_exists($path)) {
             $filePath = $path;
             break;
         }
         if (file_exists($path . ".gz")) {
             $filePath = $path . ".gz";
             $zipped = true;
             break;
         }
     }
     if ($zipped && is_file($filePath) && is_readable($filePath)) {
         $data = gzdecode(file_get_contents($filePath));
     } elseif (is_file($filePath) && is_readable($filePath)) {
         $data = file_get_contents($filePath);
     }
     if (!$data) {
         \Logger::err("Version: cannot read version data from file system.");
         $this->delete();
         return;
     }
     if ($this->getSerialized()) {
         $data = Serialize::unserialize($data);
     }
     if ($data instanceof Asset && file_exists($this->getBinaryFilePath())) {
         $binaryHandle = fopen($this->getBinaryFilePath(), "r+", false, File::getContext());
         $data->setStream($binaryHandle);
     } elseif ($data instanceof Asset && $data->data) {
         // this is for backward compatibility
         $data->setData($data->data);
     }
     $data = Element\Service::renewReferences($data);
     $this->setData($data);
     return $data;
 }
Example #3
0
 /**
  * @param $name
  * @param $type
  * @return array
  */
 public function mysqlData($name, $type)
 {
     $db = Db::reset();
     $dumpData = "\n\n";
     $name = $db->quoteTableAs($name);
     if ($type != "VIEW") {
         // backup tables
         $tableData = $db->fetchAll("SELECT * FROM " . $name);
         foreach ($tableData as $row) {
             $cells = [];
             foreach ($row as $cell) {
                 if (is_string($cell)) {
                     $cell = $db->quote($cell);
                 } elseif ($cell === null) {
                     $cell = "NULL";
                 }
                 $cells[] = $cell;
             }
             $dumpData .= "INSERT INTO " . $name . " VALUES (" . implode(",", $cells) . ");";
             $dumpData .= "\n";
         }
     } else {
         // dump view structure
         $dumpData .= "\n\n";
         $dumpData .= "DROP VIEW IF EXISTS " . $name . ";";
         $dumpData .= "\n";
         try {
             $viewData = $db->fetchRow("SHOW CREATE VIEW " . $name);
             $dumpData .= $viewData["Create View"] . ";";
         } catch (\Exception $e) {
             Logger::error($e);
         }
     }
     $dumpData .= "\n\n";
     $h = fopen(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql", "a+", false, File::getContext());
     fwrite($h, $dumpData);
     fclose($h);
     return ["success" => true];
 }
Example #4
0
 /**
  * returns the path to a temp file
  * @return string
  */
 public function getTemporaryFile()
 {
     $destinationPath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/asset-temporary/asset_" . $this->getId() . "_" . md5(microtime()) . "__" . $this->getFilename();
     if (!is_dir(dirname($destinationPath))) {
         File::mkdir(dirname($destinationPath));
     }
     $src = $this->getStream();
     $dest = fopen($destinationPath, "w+", false, File::getContext());
     stream_copy_to_stream($src, $dest);
     fclose($dest);
     @chmod($destinationPath, File::getDefaultMode());
     return $destinationPath;
 }
Example #5
0
 /**
  * @param Element\ElementInterface $element
  */
 public function restoreChilds(Element\ElementInterface $element)
 {
     $restoreBinaryData = function ($element, $scope) {
         // assets are kinda special because they can contain massive amount of binary data which isn't serialized, we create separate files for them
         if ($element instanceof Asset) {
             $binFile = $scope->getStorageFileBinary($element);
             if (file_exists($binFile)) {
                 $binaryHandle = fopen($binFile, "r", false, File::getContext());
                 $element->setStream($binaryHandle);
             }
         }
     };
     $restoreBinaryData($element, $this);
     $element->save();
     if (method_exists($element, "getChilds")) {
         if ($element instanceof Object\AbstractObject) {
             // don't use the getter because this will return an empty array (variants are excluded by default)
             $childs = $element->o_childs;
         } else {
             $childs = $element->getChilds();
         }
         foreach ($childs as $child) {
             $this->restoreChilds($child);
         }
     }
 }