/** * Apply the Revcheck tools recursively on all lang * * @param $path The directory from which we start. * @param $revType Can be 'new' when we start a new revcheck with a clean database or 'update' when we revcheck just one folder (and all is sub-folders). Default to 'new' * @param $revLang The lang we want to apply the recheck. By default, it's 'all' lang available. * @return Nothing. */ public function applyRevCheck($path = '/', $revType = 'new', $revLang = 'all') { $am = AccountManager::getInstance(); $appConf = $am->appConf; $project = $am->project; if ($dh = @opendir($appConf[$project]['vcs.path'] . 'en' . $path)) { $dirs = array(); $files = array(); while (($name = readdir($dh)) !== false) { if ($name == '.' || $name == '..') { continue; } $file = new File('en', $path . $name); if (!$this->needParsing($file)) { continue; } if ($file->isDir) { $dirs[] = $file; } elseif ($file->isFile) { $files[] = $file; } } closedir($dh); foreach ($files as $f) { $en_size = intval(filesize($f->full_path) / 1024); $en_date = filemtime($f->full_path); $infoEN = $f->getInfo(); $en_revision = $infoEN['rev'] == 'NULL' ? 'NULL' : $infoEN['rev']; $xmlid = $infoEN['xmlid'] == 'NULL' ? 'NULL' : $infoEN['xmlid']; $tmp = explode('/', $f->path); // Only for Php project if ($project == 'PHP') { $check_doc = new ToolsCheckDoc(); $ToolsCheckDocResult = $check_doc->checkDoc($infoEN['content'], $f->path); } else { $ToolsCheckDocResult['check_oldstyle'] = 'NULL'; $ToolsCheckDocResult['check_undoc'] = 'NULL'; $ToolsCheckDocResult['check_roleerror'] = 'NULL'; $ToolsCheckDocResult['check_badorder'] = 'NULL'; $ToolsCheckDocResult['check_noseealso'] = 'NULL'; $ToolsCheckDocResult['check_noreturnvalues'] = 'NULL'; $ToolsCheckDocResult['check_noparameters'] = 'NULL'; $ToolsCheckDocResult['check_noexamples'] = 'NULL'; $ToolsCheckDocResult['check_noerrors'] = 'NULL'; } // If the type of this revcheck is an update, we start to remove all reference to this file from... if ($revType == 'update') { //... table `files` $query = 'DELETE FROM `files` WHERE `project`="%s" AND `lang`="en" AND `path`="%s" AND `name`="%s"'; $params = array($am->project, $f->path, $f->name); $this->conn->query($query, $params); //... table `errorfiles` $query = 'DELETE FROM `errorfiles` WHERE `project`="%s" AND `lang`="en" AND `path`="%s" AND `name`="%s"'; $params = array($am->project, $f->path, $f->name); $this->conn->query($query, $params); } // Sql insert. $query = 'INSERT INTO `files` (`project`, `lang`, `xmlid`, `path`, `name`, `revision`, `size`, `mdate`, `maintainer`, `status`, `check_oldstyle`, `check_undoc`, `check_roleerror`, `check_badorder`, `check_noseealso`, `check_noreturnvalues`, `check_noparameters`, `check_noexamples`, `check_noerrors`) VALUES ("%s", "en", "%s", "%s", "%s", "%s", "%s", "%s", NULL, NULL, "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")'; $params = array($am->project, $xmlid, $f->path, $f->name, $en_revision, $en_size, $en_date, $ToolsCheckDocResult['check_oldstyle'], $ToolsCheckDocResult['check_undoc'], $ToolsCheckDocResult['check_roleerror'], $ToolsCheckDocResult['check_badorder'], $ToolsCheckDocResult['check_noseealso'], $ToolsCheckDocResult['check_noreturnvalues'], $ToolsCheckDocResult['check_noparameters'], $ToolsCheckDocResult['check_noexamples'], $ToolsCheckDocResult['check_noerrors']); $this->conn->query($query, $params); /* $error = new ToolsError(); $error->setParams($infoEN['content'], '', 'en', $f->path, $f->name, ''); $error->run(); $error->saveError(); */ if ($revType == 'update') { // If we are in update, we have 2 case. $revLang can be en or LANG. // If revLang is en, we must re-check all available language to reflect changes. if ($revLang == 'en') { $ExistingLanguage = $this->getExistingLanguage(); } else { $ExistingLanguage[] = array("code" => $revLang); } } else { // If this is not an update, we check all languages $ExistingLanguage = $this->getExistingLanguage(); } foreach ($ExistingLanguage as $lang) { $lang = $lang["code"]; // We skip en language if ($lang == 'en') { continue; } $lang_file = new File($lang, $f->path . $f->name); // If the type of this revcheck is an update, we start be delete all reference to this file in table... if ($revType == 'update') { // ... `file` $query = 'DELETE FROM `files` WHERE `project`="%s" AND `lang`="%s" AND `path`="%s" AND `name`="%s"'; $params = array($project, $lang, $lang_file->path, $lang_file->name); $this->conn->query($query, $params); //... table `errorfiles` $query = 'DELETE FROM `errorfiles` WHERE `project`="%s" AND `lang`="%s" AND `path`="%s" AND `name`="%s"'; $params = array($project, $lang, $lang_file->path, $lang_file->name); $this->conn->query($query, $params); } if ($lang_file->exist()) { // Initial revcheck method $size = intval(filesize($lang_file->full_path) / 1024); $date = filemtime($lang_file->full_path); $size_diff = $en_size - $size; $date_diff = intval((time() - $en_date) / 86400) - intval((time() - $date) / 86400); $infoLANG = $lang_file->getInfo(); $revision = $infoLANG['en-rev'] == 'NULL' ? 'NULL' : $infoLANG['en-rev']; $maintainer = $infoLANG['maintainer'] == 'NULL' ? 'NULL' : $infoLANG['maintainer']; $status = $infoLANG['status'] == 'NULL' ? 'NULL' : $infoLANG['status']; $xmlid = $infoLANG['xmlid'] == 'NULL' ? 'NULL' : $infoLANG['xmlid']; $reviewed = $infoLANG['reviewed'] == 'NULL' ? 'NULL' : $infoLANG['reviewed']; $reviewed_maintainer = $infoLANG['reviewed_maintainer'] == 'NULL' ? 'NULL' : $infoLANG['reviewed_maintainer']; $query = 'INSERT INTO `files` (`project`, `lang`, `xmlid`, `path`, `name`, `revision`, `en_revision`, `reviewed`, `reviewed_maintainer`, `size`, `size_diff`, `mdate`, `mdate_diff`, `maintainer`, `status`) VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")'; $params = array($project, $lang, $xmlid, $lang_file->path, $lang_file->name, $revision, $en_revision, $reviewed, $reviewed_maintainer, $size, $size_diff, $date, $date_diff, $maintainer, $status); $this->conn->query($query, $params); /* // Check for error in this file ONLY if this file is uptodate if ($revision == $en_revision && $revision != 0 ) { $error = new ToolsError(); $error->setParams( $infoEN['content'], $infoLANG['content'], $lang, $lang_file->path, $lang_file->name, $maintainer ); $error->run(); $error->saveError(); } */ } else { $query = 'INSERT INTO `files` (`project`, `lang`, `path`, `name`, `size`) VALUES ("%s", "%s", "%s", "%s", "%s")'; $params = array($project, $lang, $lang_file->path, $lang_file->name, $en_size); $this->conn->query($query, $params); } } } foreach ($dirs as $d) { $this->applyRevCheck($d->path, $revType, $revLang); } } }
/** * Get all files about the CheckDoc's tools (ToolsCheckDoc's class). */ public function getCheckDocFiles() { if (!AccountManager::getInstance()->isLogged()) { return JsonResponseBuilder::failure(); } $path = $this->getRequestVariable('path'); $errorType = $this->getRequestVariable('errorType'); $ToolsCheckDoc = new ToolsCheckDoc(); $r = $ToolsCheckDoc->getCheckDocFiles($path, $errorType); return JsonResponseBuilder::success(array('files' => $r)); }