コード例 #1
0
ファイル: Admin.php プロジェクト: burbuja/indefero
 public function usherServerControl($request, $match)
 {
     $server = $match[1];
     if (!in_array($server, IDF_Scm_Monotone_Usher::getServerList())) {
         throw new Pluf_HTTP_Error404();
     }
     $action = $match[2];
     if (!in_array($action, array('start', 'stop', 'kill'))) {
         throw new Pluf_HTTP_Error404();
     }
     $msg = null;
     if ($action == 'start') {
         IDF_Scm_Monotone_Usher::startServer($server);
         $msg = sprintf(__('The server "%s" has been started'), $server);
     } else {
         if ($action == 'stop') {
             IDF_Scm_Monotone_Usher::stopServer($server);
             $msg = sprintf(__('The server "%s" has been stopped'), $server);
         } else {
             IDF_Scm_Monotone_Usher::killServer($server);
             $msg = sprintf(__('The server "%s" has been killed'), $server);
         }
     }
     $request->user->setMessage($msg);
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_Admin::usher');
     return new Pluf_HTTP_Response_Redirect($url);
 }
コード例 #2
0
ファイル: SyncMonotone.php プロジェクト: burbuja/indefero
 /**
  * Clean up after a mtn project was deleted
  *
  * @param IDF_Project
  */
 public function processProjectDelete($project)
 {
     if ($project->getConf()->getVal('scm') != 'mtn') {
         return;
     }
     if (Pluf::f('mtn_db_access', 'local') == 'local') {
         return;
     }
     $usher_config = Pluf::f('mtn_usher_conf', false);
     if (!$usher_config || !is_writable($usher_config)) {
         throw new IDF_Scm_Exception(__('"mtn_usher_conf" does not exist or is not writable.'));
     }
     $shortname = $project->shortname;
     IDF_Scm_Monotone_Usher::killServer($shortname);
     $projecttempl = Pluf::f('mtn_repositories', false);
     if ($projecttempl === false) {
         throw new IDF_Scm_Exception(__('"mtn_repositories" must be defined in your configuration file.'));
     }
     $projectpath = sprintf($projecttempl, $shortname);
     if (file_exists($projectpath)) {
         if (!self::_delete_recursive($projectpath)) {
             throw new IDF_Scm_Exception(sprintf(__('One or more paths underknees %s could not be deleted.'), $projectpath));
         }
     }
     $keydir = Pluf::f('tmp_folder') . '/mtn-client-keys';
     $keyname = $project->getConf()->getVal('mtn_client_key_name', false);
     $keyhash = $project->getConf()->getVal('mtn_client_key_hash', false);
     if ($keyname && $keyhash && file_exists($keydir . '/' . $keyname . '.' . $keyhash)) {
         if (!@unlink($keydir . '/' . $keyname . '.' . $keyhash)) {
             throw new IDF_Scm_Exception(sprintf(__('Could not delete client private key %s'), $keyname));
         }
     }
     $usher_rc = file_get_contents($usher_config);
     $parsed_config = array();
     try {
         $parsed_config = IDF_Scm_Monotone_BasicIO::parse($usher_rc);
     } catch (Exception $e) {
         throw new IDF_Scm_Exception(sprintf(__('Could not parse usher configuration in "%s": %s'), $usher_config, $e->getMessage()));
     }
     foreach ($parsed_config as $idx => $stanzas) {
         foreach ($stanzas as $stanza_line) {
             if ($stanza_line['key'] == 'server' && $stanza_line['values'][0] == $shortname) {
                 unset($parsed_config[$idx]);
                 break;
             }
         }
     }
     $usher_rc = IDF_Scm_Monotone_BasicIO::compile($parsed_config);
     // FIXME: more sanity - what happens on failing writes? we do not
     // have a backup copy of usher.conf around...
     if (file_put_contents($usher_config, $usher_rc, LOCK_EX) === false) {
         throw new IDF_Scm_Exception(sprintf(__('Could not write usher configuration file "%s"'), $usher_config));
     }
     IDF_Scm_Monotone_Usher::reload();
 }