From 2ab52e7eaf2c72deb196aecb7f3c9104523668ad Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Thu, 25 Jun 2009 21:37:46 +0200 Subject: [PATCH] Added the possible deletion of the repository when deleting a subversion project. --- doc/syncsvn.mdtext | 2 ++ src/IDF/Plugin/SyncSvn.php | 35 ++++++++++++++++++++++++++++++++++- src/IDF/Project.php | 22 ++++++++++++++++++++++ src/IDF/relations.php | 3 ++- 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/doc/syncsvn.mdtext b/doc/syncsvn.mdtext index 085f222..67b09d6 100644 --- a/doc/syncsvn.mdtext +++ b/doc/syncsvn.mdtext @@ -66,6 +66,8 @@ need to put the following in your configuration file: $cfg['idf_plugin_syncsvn_authz_file'] = '/home/svn/dav_svn.authz'; $cfg['idf_plugin_syncsvn_passwd_file'] = '/home/svn/dav_svn.passwd'; $cfg['idf_plugin_syncsvn_svn_path'] = '/home/svn/repositories'; + // Delete the corresponding repository when deleting the project + $cfg['idf_plugin_syncsvn_remove_orphans'] = false; You can have more control over the permissions given to the owners, members, extra authorized users and anonymous users if you want with diff --git a/src/IDF/Plugin/SyncSvn.php b/src/IDF/Plugin/SyncSvn.php index 08e8eed..8aa3c49 100644 --- a/src/IDF/Plugin/SyncSvn.php +++ b/src/IDF/Plugin/SyncSvn.php @@ -52,6 +52,9 @@ class IDF_Plugin_SyncSvn case 'Pluf_User::passwordUpdated': $plug->processSyncPasswd($params['user']); break; + case 'IDF_Project::preDelete': + $plug->processSvnDelete($params['project']); + break; } } @@ -83,6 +86,31 @@ class IDF_Plugin_SyncSvn $ll = exec($cmd, $output, $return); return ($return == 0); } + + /** + * Remove the project from the drive and update the access rights. + * + * @param IDF_Project + * @return bool Success + */ + function processSvnDelete($project) + { + if (!Pluf::f('idf_plugin_syncsvn_remove_orphans', false)) { + return; + } + if ($project->getConf()->getVal('scm') != 'svn') { + return false; + } + $this->SyncAccess($project); // exclude $project + $shortname = $project->shortname; + if (false===($svn_path=Pluf::f('idf_plugin_syncsvn_svn_path',false))) { + throw new Pluf_Exception_SettingError("'idf_plugin_syncsvn_svn_path' must be defined in your configuration file."); + } + if (file_exists($svn_path.'/'.$shortname)) { + $cmd = Pluf::f('idf_exec_cmd_prefix', '').'rm -rf '.$svn_path.'/'.$shortname; + exec($cmd); + } + } /** * Synchronise an user's password. @@ -156,8 +184,10 @@ class IDF_Plugin_SyncSvn * We rebuild the complete file each time. This is just to be sure * not to bork the rights when trying to just edit part of the * file. + * + * @param IDF_Project Possibly exclude a project (null) */ - function SyncAccess() + function SyncAccess($exclude=null) { $authz_file = Pluf::f('idf_plugin_syncsvn_authz_file'); $access_owners = Pluf::f('idf_plugin_syncsvn_access_owners', 'rw'); @@ -170,6 +200,9 @@ class IDF_Plugin_SyncSvn } $fcontent = ''; foreach (Pluf::factory('IDF_Project')->getList() as $project) { + if ($exclude and $exclude->id == $project->id) { + continue; + } $conf = new IDF_Conf(); $conf->setProject($project); if ($conf->getVal('scm') != 'svn' or diff --git a/src/IDF/Project.php b/src/IDF/Project.php index 1c5b1ef..cdef2e6 100644 --- a/src/IDF/Project.php +++ b/src/IDF/Project.php @@ -586,6 +586,28 @@ class IDF_Project extends Pluf_Model */ public function preDelete() { + /** + * [signal] + * + * IDF_Project::preDelete + * + * [sender] + * + * IDF_Project + * + * [description] + * + * This signal allows an application to perform special + * operations at the deletion of a project. + * + * [parameters] + * + * array('project' => $project) + * + */ + $params = array('project' => $this); + Pluf_Signal::send('IDF_Project::preDelete', + 'IDF_Project', $params); $what = array('IDF_Upload', 'IDF_Review', 'IDF_Issue', 'IDF_WikiPage', 'IDF_Commit', ); diff --git a/src/IDF/relations.php b/src/IDF/relations.php index c1e482f..b0d7da2 100644 --- a/src/IDF/relations.php +++ b/src/IDF/relations.php @@ -54,7 +54,8 @@ Pluf_Signal::connect('IDF_Project::created', array('IDF_Plugin_SyncSvn', 'entry')); Pluf_Signal::connect('Pluf_User::passwordUpdated', array('IDF_Plugin_SyncSvn', 'entry')); - +Pluf_Signal::connect('IDF_Project::preDelete', + array('IDF_Plugin_SyncSvn', 'entry')); # # Mercurial synchronization Pluf_Signal::connect('IDF_Project::membershipsUpdated',