19 private $_modTimeCachePrefix =
'__modTime__';
36 $mainAttributes = array(
45 if ($this->usePersonalisation) {
46 return array_merge($mainAttributes, $this->personalisationFields);
48 return $mainAttributes;
62 if ($this->_haveNewestVersion($path)) {
63 return $this->_takeFromFileSystem($path);
65 return $this->_takeAndSaveFromApi($path);
69 public function getStartPage($folderPath, $locale)
71 $localizedAttributeName = Yii::app()->getModule(
'contentSource')->localizedAttributeName. $locale;
73 $folderObject = $this->
getRepositoryApi()->getContentAttributes($folderPath, array($localizedAttributeName));
75 return $folderObject[$localizedAttributeName];
87 private function _takeAndSaveFromApi($path)
90 $this->_createFile($path, $cmsObject[
'attributes'][
'content'], $cmsObject[
'attributes'][
'updatetimestamp']);
91 $content =
new Content($this, $path);
92 unset($cmsObject[
'attributes'][
'content']);
93 $content->setAttributes($cmsObject[
'attributes']);
107 private function _haveNewestVersion($path)
110 if (!file_exists($contentFile)) {
114 if ($lastModificationTime = $this->
getRepositoryApi()->getLastModificationTime($path)) {
116 Yii::app()->cache->get($this->_modTimeCachePrefix . $path) == $lastModificationTime ||
117 filemtime($this->
contentFile($path)) == $lastModificationTime;
130 private function _takeFromFileSystem($path)
134 $content =
new Content($this, $path);
153 private function _createFile($path, $content, $time)
156 if (file_exists($contentFile) && !$this->
fileAccessible($contentFile, $this->cacheFolder)) {
160 $dirPath = pathinfo($contentFile, PATHINFO_DIRNAME);
161 if (!file_exists($dirPath)) {
162 if (!@mkdir($dirPath, 0777,
true)) {
163 throw new Exception(
"Can't create dir $dirPath");
166 if (!file_put_contents($contentFile, $content)) {
167 throw new Exception(
"Can't create file $contentFile");
169 if (!touch($contentFile, $time)) {
170 throw new Exception(
"Can't touch() file $contentFile");
172 if (!chmod($contentFile, 0666)) {
173 throw new Exception(
"Can't chmod() file $contentFile");
177 unlink($contentFile);
181 Yii::app()->cache->set($this->_modTimeCachePrefix . $path, $time, Yii::app()->getModule(
'contentSource')->cacheTime);
195 return $this->cacheFolder . $path;