/** * récupère les infos du document à partir d'un fichier DocBook * @param string $fichier nom du fichier * @return boolean <code>true</code> lorsque tout s'est bien passé */ function setContentFromDocbook($fichier) { if (is_array($this->infos = docbookGetArticleInfoFromFile($fichier))) { $this->errors = array_merge($this->errors, $this->infos); $this->infos = null; return false; } $this->type = new DocumentType($this->infos->type); if (!$this->type) { $this->errors[] = "type de document inconnu"; return false; } if (!$this->infos->verifyRepertoire()) { $this->errors[] = 'répertoire indéfini'; return false; } /* lorsque l'article est tout nouveau, on vérifie en base si le nom du répertoire est unique */ $newdoc = false; if (!is_int($this->id)) { $newdoc = true; $sql = 'SELECT count(doc_id) as cnt FROM doc_document WHERE lower(doc_repertoire) = ' . $this->db->quote(strtolower($this->infos->repertoire)); $rep = $this->db->getRow($sql); if (DB::isError($rep)) { $this->errors[] = "impossible de lire depuis la base de données"; return false; } if (intval($rep['cnt']) > 0) { $this->errors[] = "donnez un autre nom de répertoire : " . $this->infos->repertoire . " est déjà utilisé"; return false; } } if (in_array($this->type->repertoire . $this->infos->repertoire, $GLOBALS['OW_FORBIDDEN_DIR'])) { $this->errors[] = "nom de répertoire interdit"; return false; } // vérification que le répertoire n'est pas verrouillé $destdir = PATH_SITE_ROOT . $this->getDocumentPath(); if (file_exists($destdir . ".lock")) { $this->errors[] = 'verrou existant, aucune action possible'; return false; } // vérification des propriétes if (!$this->_verifyProperties()) { return false; } if (count($this->errors) != 0) { return false; } // création du répertoire de l'article dans temp umask(022); touch($destdir . ".lock"); if (!file_exists($destdir)) { mkdir($destdir, 0755); mkdir($destdir . "/annexes", 0755); } $docbook_name = $this->getDocumentFileName('docbook'); // copie du fichier uploadé rename($fichier, $docbook_name); chmod($docbook_name, 0644); // enregistrement en base des différentes infos if (count($this->errors) == 0) { $this->_saveDb(); unlink($destdir . ".lock"); } else { unlink($destdir . ".lock"); return false; } if ($newdoc) { $etat = $this->ref->getStatusInfos('OW_STATUS_TEMP'); $this->changeEtat($etat['id']); } if ($this->type->isintro) { $this->ref->dumpClassements(); } // conversion du fichier dans les autres formats $this->generation(); return true; }
/** * récupère les infos du document à partir d'un fichier DocBook * @param string $fichier nom du fichier * @return boolean <code>true</code> lorsque tout s'est bien passé */ function setContentFromDocbook($fichier) { require_once PATH_INC_BACKEND_SERVICE . "DocbookParse.lib.php"; $errors =& PEAR_ErrorStack::singleton('OpenWeb_Backend_DocbookParse'); $errors->pushCallback(array(&$this, '_repackageErrorStack')); $this->infos = docbookGetArticleInfoFromFile($fichier); $this->infos->verifyRepertoire(); $errors->popCallback(); if ($this->errors->hasErrors()) { return false; } $errors =& PEAR_ErrorStack::singleton('OpenWeb_Backend_DocumentType'); $errors->pushCallback(array(&$this, '_repackageErrorStack')); $this->type = new DocumentType($this->infos->type); $errors->popCallback(); if ($this->errors->hasErrors()) { return false; } /* lorsque l'article est tout nouveau, on vérifie en base si le nom du répertoire est unique */ $newdoc = false; if (!is_int($this->id)) { $newdoc = true; $sql = 'SELECT count(doc_id) as cnt FROM doc_document WHERE lower(doc_repertoire) = ' . $this->db->quote(strtolower($this->infos->repertoire)); $rep = $this->db->getRow($sql); if (DB::isError($rep)) { $this->errors->push(17); /*impossible de lire depuis la base de données*/ return false; } if (intval($rep['cnt']) > 0) { $this->errors->push(17); /*"donnez un autre nom de répertoire : ".$this->infos->repertoire." est déjà utilisé";*/ return false; } } if (in_array($this->type->repertoire . $this->infos->repertoire, $GLOBALS['OW_FORBIDDEN_DIR'])) { $this->errors->push(17); /*"nom de répertoire interdit pas l'admin*/ return false; } $destdir = PATH_SITE_ROOT . $this->getDocumentPath(); // vérification des propriétes $this->_validateProperties(); if ($this->errors->hasErrors()) { return false; } // création du répertoire de l'article dans temp umask(022); if (file_exists($destdir)) { if (!is_dir($destdir)) { $this->errors->push(17); } /* @todo error code */ } else { mkdir($destdir, 0755); } $annexes = $destdir . "/annexes"; if (file_exists($annexes)) { if (!is_dir($annexes)) { $this->errors->push(17); } /* @todo error code */ } else { mkdir($annexes, 0755); } $dbkfile = $this->getDocumentFileName('docbook'); /* @todo traiter les erreurs ici */ $fl = new FileLock(); ignore_user_abort(true); $fp = $fl->Open($dbkfile); fwrite($fp, file_get_contents($fichier)); $fl->Close($fp); ignore_user_abort(false); chmod($dbkfile, 0644); if ($this->errors->hasErrors()) { return false; } // enregistrement en base des différentes infos $this->_saveDb(); if ($newdoc) { $etat = $this->ref->getStatusInfos('OW_STATUS_TEMP'); $this->changeEtat($etat['id']); } if ($this->type->isintro) { $this->ref->dumpClassements(); } // conversion du fichier dans les autres formats $this->generation(); return !$this->errors->hasErrors(); }