Esempio n. 1
0
 public static function observeCssGroupFolder($groupId)
 {
     $objCss = ExtCssModel::findByPk($groupId);
     if ($objCss === null || $objCss->observeFolderSRC == '') {
         return false;
     }
     $objObserveModel = \FilesModel::findByUuid($objCss->observeFolderSRC);
     if ($objObserveModel === null || !is_dir(TL_ROOT . '/' . $objObserveModel->path)) {
         return false;
     }
     $lastUpdate = filemtime(TL_ROOT . '/' . $objObserveModel->path);
     // check if folder content has updated
     if ($lastUpdate <= $objObserveModel->tstamp) {
         return false;
     }
     $objCssFiles = ExtCssFileModel::findMultipleByPids(array($groupId));
     $arrOldFileNames = array();
     if ($objCssFiles !== null) {
         $objCssFilesModel = \FilesModel::findMultipleByUuids($objCssFiles->fetchEach('src'));
         if ($objCssFilesModel !== null) {
             $arrOldFileNames = $objCssFilesModel->fetchEach('path');
         }
     }
     $arrFileNames = static::scanLessFiles($objObserveModel->path);
     $arrDiff = array_diff($arrFileNames, $arrOldFileNames);
     // exclude bootstrap variables src
     $objVariablesModel = \FilesModel::findMultipleByUuids(deserialize($objCss->variablesOrderSRC, true));
     $arrRemove = array();
     if ($objVariablesModel !== null) {
         $arrVariables = $objVariablesModel->fetchEach('path');
         // remove variables from oberserve files
         $arrDiff = array_diff($arrDiff, $arrVariables);
         // remove variables from oberserve files
         $arrRemove = array_intersect($arrOldFileNames, $arrVariables);
     }
     if (!empty($arrDiff)) {
         // add new files
         foreach ($arrDiff as $key => $path) {
             static::addCssFileToGroup($path, $groupId);
         }
     }
     // cleanup
     $arrRemove = array_merge($arrRemove, array_diff($arrOldFileNames, $arrFileNames));
     if (!empty($arrRemove)) {
         // add new files
         foreach ($arrRemove as $key => $path) {
             // file is not part of the observed folder
             if (strpos($path, $objObserveModel->path) === FALSE) {
                 continue;
             }
             static::removeCssFileFromGroup($path, $groupId);
         }
     }
     return true;
 }
 protected function addCssFiles()
 {
     $objFiles = ExtCssFileModel::findMultipleByPids($this->ids, array('order' => 'FIELD(pid, ' . implode(",", $this->ids) . '), sorting DESC'));
     if ($objFiles === null) {
         return false;
     }
     while ($objFiles->next()) {
         $objFileModel = \FilesModel::findByPk($objFiles->src);
         if ($objFileModel === null) {
             continue;
         }
         if (!file_exists(TL_ROOT . '/' . $objFileModel->path)) {
             continue;
         }
         $objFile = new \File($objFileModel->path);
         if ($objFile->size == 0) {
             continue;
         }
         if ($this->isFileUpdated($objFile, $this->objUserCssFile)) {
             $this->rewrite = true;
         }
         $this->objLess->parseFile($objFile->value);
     }
 }