renewReferences() public static method

renews all references, for example after unserializing an ElementInterface
public static renewReferences ( Document | Asset | AbstractObject $data, $initial = true ) : mixed
$data Pimcore\Model\Document | Pimcore\Model\Asset | Pimcore\Model\Object\AbstractObject
return mixed
示例#1
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+");
         $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;
 }