svn: /web/doc-editor/trunk/php/ ExtJsController.php File.php RepositoryFetcher.php RepositoryManager.php SvnClient.php
[email protected] (Yannick Torres)
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <[email protected]> |
yannick Sat, 12 Dec 2009 07:48:27 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=292023
Log:
Now, when a user translate a file from a folder witch don't exist in this LANG, the folder is created and placed into PendingCommit DB table. When a user who have commit privilege commit some files, this folder is also commited.
Changed paths:
U web/doc-editor/trunk/php/ExtJsController.php
U web/doc-editor/trunk/php/File.php
U web/doc-editor/trunk/php/RepositoryFetcher.php
U web/doc-editor/trunk/php/RepositoryManager.php
U web/doc-editor/trunk/php/SvnClient.php
svn-diffs-292023.txt
(text/x-diff, 10.8 KB)
Modified: web/doc-editor/trunk/php/ExtJsController.php
===================================================================
--- web/doc-editor/trunk/php/ExtJsController.php 2009-12-12 07:44:26 UTC (rev 292022)
+++ web/doc-editor/trunk/php/ExtJsController.php 2009-12-12 07:48:27 UTC (rev 292023)
@@ -536,11 +536,9 @@
}
} else if ($type == 'trans') {
- // We must to ensure that this folder existe in the VCS repository & localy
- $vf = VCSFactory::getInstance();
+ // We must ensure that this folder exist localy
+ if( $file->folderExist() ) {
- if( $vf->folderExist($file) ) {
-
$er = $file->save($fileContent, false);
if( $er['state'] ) {
@@ -570,7 +568,6 @@
} else {
return JsonResponseBuilder::failure();
}
-
} else {
$uniqID = RepositoryManager::getInstance()->addPendingPatch(
@@ -816,13 +813,14 @@
$anode = json_decode(stripslashes($nodes));
+ $commitResponse = '';
+
// We create a lock for this commit process
$lock = new LockFile('lock_'.AccountManager::getInstance()->vcsLogin.'_commit');
if ($lock->lock()) {
- $commitResponse = '';
$commitResponse = RepositoryManager::getInstance()->commitChanges($anode, $logMessage);
Modified: web/doc-editor/trunk/php/File.php
===================================================================
--- web/doc-editor/trunk/php/File.php 2009-12-12 07:44:26 UTC (rev 292022)
+++ web/doc-editor/trunk/php/File.php 2009-12-12 07:48:27 UTC (rev 292023)
@@ -3,6 +3,7 @@
require_once dirname(__FILE__) . '/conf.inc.php';
require_once dirname(__FILE__) . '/DBConnection.php';
require_once dirname(__FILE__) . '/VCSFactory.php';
+require_once dirname(__FILE__) . '/RepositoryManager.php';
class File
{
@@ -36,9 +37,9 @@
}
/**
- * Read the content of a file.
- *
- * @param $readOriginal true to read the original content of the file, false to read the modified file (if any). By default, false.
+ * Read the content of a file.
+ *
+ * @param $readOriginal true to read the original content of the file, false to read the modified file (if any). By default, false.
* @return The content of the file.
*/
public function read($readOriginal=false)
@@ -77,6 +78,62 @@
}
/**
+ * Create a new folder localy & register it to pendingCommit
+ *
+ * @param $path path to create
+ * @return true
+ */
+ private function createFolder($path) {
+
+ // We create this folder localy
+ $cmd = 'cd '.DOC_EDITOR_VCS_PATH.'; mkdir '.$this->lang.$path;
+
+ $trial_threshold = 3;
+ while ($trial_threshold-- > 0) {
+ $output = array();
+ exec($cmd, $output);
+ if (strlen(trim(implode('', $output))) != 0) break;
+ }
+
+ // We register this new folder to be committed
+ $obj = (object) array('lang' => $this->lang, 'path' => $path, 'name' => '-');
+ RepositoryManager::getInstance()->addPendingCommit($obj, '-', '-', '-', '-', 'new');
+
+ }
+
+ /**
+ * Check if the path of this $file exist or not. If not, try to create it recursively with createFolder's method
+ *
+ * @return true
+ */
+ public function folderExist() {
+
+ $folders = array();
+ $_folders = explode("/", $this->path);
+
+ //Skip empty value
+ for( $i=0; $i < count($_folders); $i++) {
+ if( $_folders[$i] != "" ) {
+ $folders[] = $_folders[$i];
+ }
+ }
+
+ $path = '';
+
+ for( $i=0; $i < count($folders); $i++ ) {
+
+ $herePath = $path.'/'.$folders[$i];
+
+ if( !is_dir(DOC_EDITOR_VCS_PATH.$this->lang.$herePath) ) {
+ $this->createFolder($herePath);
+ }
+
+ $path = $herePath;
+ }
+ return true;
+ }
+
+ /**
* Parse an array of string to find all attributes in form of (key=value) pairs.
*
* @param $key_value_pairs Array of key-value pair strings to be parsed.
Modified: web/doc-editor/trunk/php/RepositoryFetcher.php
===================================================================
--- web/doc-editor/trunk/php/RepositoryFetcher.php 2009-12-12 07:44:26 UTC (rev 292022)
+++ web/doc-editor/trunk/php/RepositoryFetcher.php 2009-12-12 07:48:27 UTC (rev 292023)
@@ -280,15 +280,47 @@
return array('nb' => $r->num_rows, 'node' => $node);
}
+
/**
+ * Get all folders pending for commit.
+ *
+ * @return An associated array containing paths of folders pending for commit, or FALSE if there is no folder to commit.
+ */
+ public function getPendingFoldersCommit()
+ {
+
+ $s = sprintf(
+ 'SELECT * FROM `pendingCommit` WHERE (`lang`="%s" OR `lang`=\'en\') AND `name`=\'-\' ORDER BY id ASC',
+ AccountManager::getInstance()->vcsLang
+ );
+ $r = DBConnection::getInstance()->query($s);
+
+ if( $r->num_rows == 0 ) {
+ return false;
+ }
+
+ $paths = array();
+ while ($a = $r->fetch_object()) {
+
+ $obj = (object) array('lang' => $a->lang, 'path' => $a->path, 'name'=> '-');
+
+ $paths[] = $obj;
+ }
+
+ return $paths;
+ }
+
+ /**
* Get all files pending for commit.
*
* @return An associated array containing informations about files pending for commit.
*/
public function getPendingCommit()
{
+
+ // We exclude item witch name == '-' ; this is new folder ; We don't display it.
$s = sprintf(
- 'SELECT * FROM `pendingCommit` WHERE `lang`="%s" OR `lang`=\'en\'',
+ 'SELECT * FROM `pendingCommit` WHERE (`lang`="%s" OR `lang`=\'en\') AND `name` != \'-\'',
AccountManager::getInstance()->vcsLang
);
$r = DBConnection::getInstance()->query($s);
Modified: web/doc-editor/trunk/php/RepositoryManager.php
===================================================================
--- web/doc-editor/trunk/php/RepositoryManager.php 2009-12-12 07:44:26 UTC (rev 292022)
+++ web/doc-editor/trunk/php/RepositoryManager.php 2009-12-12 07:48:27 UTC (rev 292023)
@@ -243,8 +243,19 @@
*/
public function commitChanges($ids, $log)
{
- $fileInfos = RepositoryFetcher::getInstance()->getModifiesById($ids);
+ $commitLog = Array();
+
+ // Task for folders
+ $foldersInfos = RepositoryFetcher::getInstance()->getPendingFoldersCommit();
+ if( $foldersInfos ) {
+ $c = VCSFactory::getInstance()->commitFolders($foldersInfos);
+ $commitLog = array_merge($commitLog, $c);
+ $this->delPendingCommit($foldersInfos);
+ }
+
+ // Task for files
+ $fileInfos = RepositoryFetcher::getInstance()->getModifiesById($ids);
// Loop over $fileInfos to find files to be create, update or delete
$create_stack = array();
$update_stack = array();
@@ -262,9 +273,10 @@
case 'delete': $delete_stack[] = $f; break;
}
}
- $commitLog = VCSFactory::getInstance()->commit(
+ $c = VCSFactory::getInstance()->commit(
$log, $create_stack, $update_stack, $delete_stack
);
+ $commitLog = array_merge($commitLog, $c);
// html highlight commit log
$reg = array(
Modified: web/doc-editor/trunk/php/SvnClient.php
===================================================================
--- web/doc-editor/trunk/php/SvnClient.php 2009-12-12 07:44:26 UTC (rev 292022)
+++ web/doc-editor/trunk/php/SvnClient.php 2009-12-12 07:48:27 UTC (rev 292023)
@@ -216,73 +216,6 @@
return $output;
}
- /**
- * Create a new folder localy and commit it into repository
- *
- * @param $path path to create
- * @return true
- */
- private function createFolder($path) {
-
- // We create this folder localy
- $cmd = 'cd '.DOC_EDITOR_VCS_PATH.'; mkdir '.$path;
-
- $trial_threshold = 3;
- while ($trial_threshold-- > 0) {
- $output = array();
- exec($cmd, $output);
- if (strlen(trim(implode('', $output))) != 0) break;
- }
-
- // We add this new folder into repository
- $vcsLogin = AccountManager::getInstance()->vcsLogin;
- $vcsPasswd = AccountManager::getInstance()->vcsPasswd;
-
- $cmd = 'cd '.DOC_EDITOR_VCS_PATH.'; svn add '.$path.'; svn ci --no-auth-cache --non-interactive -m "Add new folder from PhpDocumentation Online Editor" --username '.$vcsLogin.' --password '.$vcsPasswd.' '.$path;
-
- $trial_threshold = 3;
- while ($trial_threshold-- > 0) {
- $output = array();
- exec($cmd, $output);
- if (strlen(trim(implode('', $output))) != 0) break;
- }
-
- return true;
- }
-
- /**
- * Check if the path of this $file exist or not. If not, try to create it recursively with createFolder's method
- *
- * @param $file path to check
- * @return true
- */
- public function folderExist($file) {
-
- $folders = array();
- $_folders = explode("/", $file->path);
-
- //Skip empty value
- for( $i=0; $i < count($_folders); $i++) {
- if( $_folders[$i] != "" ) {
- $folders[] = $_folders[$i];
- }
- }
-
- $path = $file->lang;
-
- for( $i=0; $i < count($folders); $i++ ) {
-
- $herePath = $path.'/'.$folders[$i];
-
- if( !is_dir(DOC_EDITOR_VCS_PATH.$herePath) ) {
- $this->createFolder($herePath);
- }
-
- $path = $herePath;
- }
- return true;
- }
-
public function createCommitLogFile($log)
{
$path = tempnam(sys_get_temp_dir(), 'Doc_Editor_Commit_Log_Message');
@@ -299,6 +232,28 @@
@unlink($path);
}
+ public function commitFolders($foldersPath) {
+
+ $commitLogMessage = Array();
+
+ for( $i=0; $i < count($foldersPath); $i++ ) {
+ // We add this new folder into repository
+ $vcsLogin = AccountManager::getInstance()->vcsLogin;
+ $vcsPasswd = AccountManager::getInstance()->vcsPasswd;
+
+ $cmd = 'cd '.DOC_EDITOR_VCS_PATH.'; svn add '.$foldersPath[$i]->lang.$foldersPath[$i]->path.'; svn ci --non-recursive --no-auth-cache --non-interactive -m "Add new folder from PhpDocumentation Online Editor" --username '.$vcsLogin.' --password '.$vcsPasswd.' '.$foldersPath[$i]->lang.$foldersPath[$i]->path;
+
+ $trial_threshold = 3;
+ while ($trial_threshold-- > 0) {
+ $output = array();
+ exec($cmd, $output);
+ if (strlen(trim(implode('', $output))) != 0) break;
+ }
+ $commitLogMessage = array_merge($commitLogMessage, $output);
+ }
+ return $commitLogMessage;
+ }
+
/**
* Executes svn commit
*