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;
}