Example #1
0
 public function register()
 {
     $callback = function ($node) {
         if (FileInfo::TYPE_FILE === $node->getType()) {
             $type = $this->getType($node);
             if ($type === SML) {
                 $this->sensorMLHook->onUpdateOrCreate($node->getId(), $node->getContent());
             } else {
                 if ($type === OM) {
                     $this->omHook->onUpdateOrCreate($node->getId(), $node->getContent());
                 } else {
                     if (FileUtil::endsWith($node->getName(), TAR)) {
                         $tarContent = TarParser::parse(FileCacheDao::getFullUrl($node->getId()));
                         foreach ($tarContent as $item) {
                             $path = $item['path'];
                             if ($item['file']) {
                                 if (FileUtil::endsWith($path, 'xml')) {
                                     $data = file_get_contents($path);
                                     $xml = new \SimpleXMLElement($data);
                                     if (OMParser::accept($xml)) {
                                         $this->omHook->onUpdateOrCreate($node->getId(), $data, $item['pharPath']);
                                     } else {
                                         if (SensorMLParser::accept($xml)) {
                                             $this->sensorMLHook->onUpdateOrCreate($node->getId(), $data, $item['pharPath']);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     };
     //Create or update
     $this->fileSystemManager->listen('\\OC\\Files', 'postCreate', $callback);
     $this->fileSystemManager->listen('\\OC\\Files', 'postWrite', $callback);
     //deletion
     $this->fileSystemManager->listen('\\OC\\Files', 'preDelete', function ($node) {
         if (FileInfo::TYPE_FILE === $node->getType()) {
             $type = $this->getType($node);
             if ($type === SML) {
                 $this->sensorMLHook->onDelete($node);
             } else {
                 if ($type === OM) {
                     $this->omHook->onDelete($node);
                 } else {
                     if (FileUtil::endsWith($node->getName(), TAR)) {
                         $this->sensorMLHook->onDelete($node);
                     }
                 }
             }
         }
     });
     //Si la version d'owncloud est suffisante chargement uniquement dans les cas nécessaires
     if (method_exists(\OC::$server, 'getEventDispatcher')) {
         $eventDispatcher = \OC::$server->getEventDispatcher();
         $eventDispatcher->addListener('OCA\\Files::loadAdditionalScripts', ['OCA\\SnannyOwncloudApi\\Hooks\\FileHook', "onLoadFilesAppScripts"]);
     } else {
         //Sinon chargement indifférent du script js
         onLoadFilesAppScripts();
     }
 }
 /**
  * get info of existant sml for uuid and dates
  * @param $uuid uuid du system
  * @param $from : begin time of system valid period
  * @param $to : end time of system valid period
  * @param $dir : repertoire du fichier en cour d'édition
  * @param $fileName : nom du fichier en cours d'édition
  * @return DataDisplayResponse|NotFoundResponse Reponse if document exist, otherwise raised exception
  *
  * @NoCSRFRequired
  * @NoAdminRequired
  * @PublicPage
  */
 public function smlExist($uuid, $from = null, $to = null, $dir = null, $fileName = null)
 {
     $finalDir = $dir !== null ? $dir : '';
     $path = $fileName !== null ? 'files' . $finalDir . '/' . basename($fileName, '.moe') : null;
     $systems = $this->systemMapper->getByUuidAndDateAndNotPath($uuid, $from, $to, $path);
     $data = array();
     if ($systems != null && count($systems) >= 1) {
         foreach ($systems as $system) {
             $resultDir = '';
             $resultFileName = '';
             $isMoe = false;
             $fileCache = FileCacheDao::getFileCacheByFileId($system->getFileId());
             if ($fileCache !== null) {
                 $fileCachePath = $fileCache['path'];
                 $fileCachePath = str_replace('.tar', '.moe', $fileCachePath);
                 $fileCachePath = str_replace('.xml', '.moe', $fileCachePath);
                 $moeFileCache = FileCacheDao::getFileCacheByPath($fileCachePath);
                 if ($moeFileCache !== null) {
                     $resultDir = dirname($moeFileCache['path']);
                     $resultFileName = $moeFileCache['name'];
                     $isMoe = true;
                 } else {
                     $resultDir = dirname($fileCache['path']);
                     $resultFileName = $fileCache['name'];
                 }
             }
             $data[] = array('name' => $system->getName(), 'uuid' => $system->getUuid(), 'from' => $system->getStartDate(), 'to' => $system->getEndDate(), 'dir' => str_replace("files", "", $resultDir), 'fileName' => $resultFileName, 'isMoe' => $isMoe);
         }
     }
     return new JSONResponse($data);
 }
 public static function getContent($numericId, $path)
 {
     $fileInfo = FileCacheDao::getFileInfo($numericId, $path);
     return FileCacheDao::getContentByUrn($fileInfo['urn']);
 }