/**
  * Update a single folder of the repository to sync our local copy.
  */
 public function updateFolder($path)
 {
     $rf = RepositoryFetcher::getInstance();
     $am = AccountManager::getInstance();
     $project = $am->project;
     // We reset the session var
     unset($_SESSION['updateFolder']['newFolders']);
     unset($_SESSION['updateFolder']['newFiles']);
     // We search for the first folder ; can be en/ LANG/ or doc-base/ for example
     $t = explode("/", $path);
     $firstFolder = $t[1];
     array_shift($t);
     array_shift($t);
     $pathWithoutLang = '/' . implode("/", $t) . '/';
     // If we are in the root folder, we have //. We must consider this case.
     if ($pathWithoutLang == '//') {
         $pathWithoutLang = '/';
     }
     if ($firstFolder == "") {
         $firstFolder = 'root';
     }
     $lock = new LockFile('project_' . $project . '_' . $firstFolder . '_lock_update_folder');
     if ($lock->lock()) {
         if ($this->isValidLanguage($firstFolder)) {
             // This is only for EN and LANG. For others, we don't make any version's comparaison.
             // We start be get files & folders in this folder to compare it after the update
             $actual = $rf->getFilesByDirectory($path);
             $actualFiles = $actualFolders = array();
             for ($i = 0; $i < count($actual); $i++) {
                 // We get files and folders
                 if ($actual[$i]['type'] === 'folder') {
                     $actualFolders[$actual[$i]['text']] = array("name" => $actual[$i]['text']);
                 } else {
                     $actualFiles[$actual[$i]['text']] = array("name" => $actual[$i]['text'], "version" => "");
                 }
             }
             // We get versions for this files
             while (list($k, $v) = each($actualFiles)) {
                 $file = new File($firstFolder, $pathWithoutLang . $k);
                 $info = $file->getInfo();
                 $actualFiles[$k]['version'] = $info['rev'];
             }
         }
         // We update the repository recursively
         VCSFactory::getInstance()->updateSingleFolder($path);
         if ($this->isValidLanguage($firstFolder)) {
             // We throw the revCheck on this folder only if the langue is valide
             $this->applyRevCheck($pathWithoutLang, 'update', $firstFolder);
             // We get files under this folder to make comparaison after the update
             $now = $rf->getFilesByDirectory($path);
             $nowFiles = $nowFolders = array();
             for ($i = 0; $i < count($now); $i++) {
                 // We get all folders & files
                 if ($now[$i]['type'] === 'folder') {
                     $nowFolders[$now[$i]['text']] = array("name" => $now[$i]['text']);
                 } else {
                     $nowFiles[$now[$i]['text']] = array("name" => $now[$i]['text'], "version" => "");
                 }
             }
             // We get versions of this files
             while (list($k, $v) = each($nowFiles)) {
                 $file = new File($firstFolder, $pathWithoutLang . $k);
                 $info = $file->getInfo();
                 $nowFiles[$k]['version'] = $info['rev'];
             }
             //~ debug(json_encode($nowFiles));
             //~ debug(json_encode($actualFiles));
             // We search for differences
             reset($nowFiles);
             reset($nowFolders);
             while (list($k, $v) = each($nowFiles)) {
                 // If the file exist before, and at the same version, we delete it from $nowFiles
                 if (isset($actualFiles[$k]) && $actualFiles[$k]['version'] == $v['version']) {
                     unset($nowFiles[$k]);
                 }
             }
             while (list($k, $v) = each($nowFolders)) {
                 // If the folder exist before, we delete it from $nowFolders
                 if (isset($actualFolders[$k])) {
                     unset($nowFolders[$k]);
                 }
             }
             // $nowFolders contains only new folders who don't exist before the update
             // and $nowFiles, new files who don't exist before the update or who the version have changed
             // We store this result in session to allow get it if this processus take more than 30 seconds (max execution time)
             $_SESSION['updateFolder']['newFolders'] = $nowFolders;
             $_SESSION['updateFolder']['newFiles'] = $nowFiles;
         }
     }
     $lock->release();
     return json_encode($_SESSION['updateFolder']);
 }
Пример #2
0
/***
* This script is intended to be placed in a cronjob.
* It must be run every Thursday, at 01hOO for example.
* On Unix, you can use crontab -e and place this :
* 00 01 * * 4 /path/php/binary /path/to/your/vcs/dir/doc-editor/scripts/cron/check_entities.php
****/
require_once dirname(__FILE__) . '/../../php/Conf.php';
require_once dirname(__FILE__) . '/../../php/LockFile.php';
require_once dirname(__FILE__) . '/../../php/ProjectManager.php';
require_once dirname(__FILE__) . '/../../php/RepositoryManager.php';
require_once dirname(__FILE__) . '/../../php/ToolsCheckEntities.php';
$rm = RepositoryManager::getInstance();
$pm = ProjectManager::getInstance();
$availableProject = $pm->getAvailableProject();
while (list($key, $project) = each($availableProject)) {
    if ($project['code'] != "php") {
        continue;
    }
    // Define it as a project
    $pm->setProject($project['code']);
    $lock = new LockFile('project_' . $project['code'] . '_lock_check_entities');
    if ($lock->lock()) {
        ToolsCheckEntities::getInstance()->startCheck();
        // Set lastUpdate date/time
        $info = array();
        $info['user'] = '******';
        $rm->setStaticValue('info', 'checkEntities', json_encode($info), true);
    }
    // Remove the lock File
    $lock->release();
}
 /**
  * Commit modified files.
  */
 public function vcsCommit()
 {
     $am = AccountManager::getInstance();
     $rm = RepositoryManager::getInstance();
     if (!$am->isLogged()) {
         return JsonResponseBuilder::failure();
     }
     if (!$am->haveKarma) {
         return JsonResponseBuilder::failure();
     }
     $patchID = $this->getRequestVariable('patchID');
     $nodes = $this->getRequestVariable('nodes');
     $logMessage = stripslashes($this->getRequestVariable('logMessage'));
     $anode = json_decode(stripslashes($nodes));
     $commitResponse = $tmp = '';
     // We create a lock for this commit process
     $lock = new LockFile('project_' . $am->project . '_lock_' . $am->vcsLogin . '_commit');
     if ($lock->lock()) {
         $tmp = $rm->commitChanges($anode, $logMessage);
         $commitResponse = $tmp['commitResponse'];
         $anode = $tmp['anode'];
         $err = $tmp['err'];
         // Store the response into session to display later
         $_SESSION['commitResponse'] = $commitResponse;
         if (0 == $err) {
             // Start all process after the VCS commit (related to db changes)
             $nodes = RepositoryFetcher::getInstance()->getModifiesById($anode);
             // We need to provide a different treatment regarding the file's type...
             $existFiles = array();
             // Can be an updated file or a new file
             $deleteFiles = array();
             $j = 0;
             for ($i = 0; $i < count($nodes); $i++) {
                 if ($nodes[$i]['type'] == 'update' || $nodes[$i]['type'] == 'new') {
                     $existFiles[] = new File($nodes[$i]['lang'], $nodes[$i]['path'] . $nodes[$i]['name']);
                 }
                 if ($nodes[$i]['type'] == 'delete') {
                     $deleteFiles[$j]->lang = $nodes[$i]['lang'];
                     $deleteFiles[$j]->path = $nodes[$i]['path'];
                     $deleteFiles[$j]->name = $nodes[$i]['name'];
                     $j++;
                 }
             }
             // ... for existing Files (new or update)
             if (!empty($existFiles)) {
                 // Update revision & reviewed for all this files (LANG & EN)
                 $rm->updateFileInfo($existFiles);
                 // Remove all this files in work
                 $rm->delWork($existFiles);
             }
             // End of $existFiles stuff
             // ... for deleted Files
             if (!empty($deleteFiles)) {
                 // Remove this files from db
                 $rm->delFiles($deleteFiles);
                 // Remove all this files in work tables
                 $rm->delWork($deleteFiles);
             }
             // End of $deleteFiles stuff
             // We re-compute summary statistics for the global documentation & by translators
             $lang = AccountManager::getInstance()->vcsLang;
             $rm->updateTranslatorInfo();
             TranslationStatistic::getInstance()->computeSummary($lang);
             TranslatorStatistic::getInstance()->computeSummary($lang);
         }
     }
     // Manage log message (add new or ignore it if this message already exist for this user)
     LogManager::getInstance()->addCommitLog($logMessage);
     // We send an email only if this commit is from a patch
     if ($patchID) {
         $rm->postPatchCommit($patchID);
     }
     // Remove the lock File
     $lock->release();
     return JsonResponseBuilder::success(array('mess' => $commitResponse));
 }