/** @return Tracker */
 private function importTrackerStructure()
 {
     try {
         return $this->xml_import->createFromXMLFile($this->project->getID(), $this->template_path);
     } catch (Exception $exception) {
         $logger = new BackendLogger();
         $logger->error('Unable to create first kanban for ' . $this->project->getId() . ': ' . $exception->getMessage());
         return;
     }
 }
 public function getTopModifiedFiles(PFUser $user, TimeInterval $interval, $limit)
 {
     $where_forbidden = $this->getForbiddenPaths($user);
     $stats = array();
     $dao = $this->getDao();
     $dar = $dao->searchTopModifiedFiles($this->project->getID(), $interval, $limit, $where_forbidden);
     foreach ($dar as $row) {
         $stats[] = array('path' => $row['path'], 'commit_count' => $row['commit_count']);
     }
     return $stats;
 }
 public function updateAccessForRepositories(Project $project, $old_access, $new_access)
 {
     if ($new_access == Project::ACCESS_PRIVATE) {
         $this->git_permission_dao->disableAnonymousRegisteredAuthenticated($project->getID());
         $this->git_system_event_manager->queueProjectsConfigurationUpdate(array($project->getID()));
     }
     if ($new_access == Project::ACCESS_PUBLIC && $old_access == Project::ACCESS_PUBLIC_UNRESTRICTED) {
         $this->git_permission_dao->disableAuthenticated($project->getID());
         $this->git_system_event_manager->queueProjectsConfigurationUpdate(array($project->getID()));
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->tmp_dir = '/var/tmp';
     $this->fixtures_dir = dirname(__FILE__) . '/_fixtures';
     $this->project_id = getmypid();
     $this->project = stub('Project')->getID()->returns($this->project_id);
     $this->zip = new ZipArchive();
     if ($this->zip->open($this->fixtures_dir . '/archive.zip') !== true) {
         $this->fail('unable to open fixture archive.zip');
     }
     $this->archive = new ProjectXMLImporter_XMLImportZipArchive($this->project->getID(), $this->zip, $this->tmp_dir);
 }
 private function removePreviousCrossReferences(Project $project, $revision, $old_commit_message)
 {
     $GLOBALS['group_id'] = $project->getID();
     $references = $this->reference_manager->extractReferences($old_commit_message, $project->getID());
     foreach ($references as $reference_instance) {
         /* @var $reference Reference */
         $reference = $reference_instance->getReference();
         if ($reference) {
             $cross_reference = new CrossReference($revision, $project->getID(), ReferenceManager::REFERENCE_NATURE_SVNREVISION, '', $reference_instance->getValue(), $reference->getGroupId(), $reference->getNature(), '', '');
             $this->reference_manager->removeCrossReference($cross_reference);
         }
     }
 }
 /**
  * @return Codendi_Request
  */
 private function buildRequest(Project $project, SimpleXMLElement $xml_element)
 {
     $params['action'] = 'export';
     $params['project_id'] = $project->getID();
     $params['into_xml'] = $xml_element;
     return new Codendi_Request($params);
 }
 /**
  * @return Service[]
  */
 public function getListOfAllowedServicesForProject(Project $project)
 {
     if (!isset($this->list_of_services_per_project[$project->getID()])) {
         $this->list_of_services_per_project[$project->getID()] = array();
         $allowed_services_dar = $this->dao->searchByProjectIdAndShortNames($project->getID(), array_merge($this->list_of_core_services, $this->getListOfPluginBasedServices($project)));
         foreach ($allowed_services_dar as $row) {
             $classname = $project->getServiceClassName($row['short_name']);
             try {
                 $this->list_of_services_per_project[$project->getID()][$row['service_id']] = new $classname($project, $row);
             } catch (ServiceNotAllowedForProjectException $e) {
                 //don't display the row for this servce
             }
         }
     }
     return $this->list_of_services_per_project[$project->getID()];
 }
 /**
  * @param Project $project
  *
  * @return string
  */
 public function getUsedLanguageForProject(Project $project)
 {
     $result = $this->dao->getUsedLanguageForProject($project->getID());
     if (!$result) {
         return;
     }
     return $result['language'];
 }
 public function setProject(Project $project)
 {
     $this->project = $project;
     $url = parent::getUrl();
     $url->setQueryVar('page', 'project');
     $url->setQueryVar('id', $project->getID());
     $this->setContent($project->getName());
 }
 public function getVersionForProject(Project $project)
 {
     $row = $this->version_dao->getVersionForProject($project->getID());
     if (!$row) {
         return;
     }
     return $row['mw_version'];
 }
 public function getAllowedTagsFromWhiteList(Project $project)
 {
     $content = $this->getImmutableTagsWhitelistForProject($project->getID());
     if (!$content) {
         return array();
     }
     return explode(PHP_EOL, $content);
 }
 /**
  * @param Project $project
  * @param int     $service_id
  *
  * @return Project_Service_ServiceUsage
  */
 public function getServiceUsage(Project $project, $service_id)
 {
     $query_result = $this->dao->getServiceUsage($project->getID(), $service_id);
     $row = $query_result->getRow();
     if ($row) {
         return $this->getInstanceFromRow($row);
     }
     return null;
 }
Example #13
0
 protected function getReport(PFUser $user, Project $project)
 {
     $name = $GLOBALS['Language']->getText('plugin_tracker_homenav', 'search');
     $is_query_displayed = Toggler::shouldBeDisplayed($user, 'tracker_report_query_0', true);
     $report_id = $description = $current_renderer_id = $parent_report_id = $user_id = $is_default = $tracker_id = $updated_by = $updated_at = 0;
     $report = new Tracker_Report($report_id, $name, $description, $current_renderer_id, $parent_report_id, $user_id, $is_default, $tracker_id, $is_query_displayed, $updated_by, $updated_at);
     $report->setProjectId($project->getID());
     return $report;
 }
 /**
  * @param string $project
  */
 public function __construct(Project $project)
 {
     $this->logger = new BackendLogger();
     $this->project = $project;
     $this->project_name = $project->getUnixName();
     $this->project_id = $project->getID();
     $this->dao = new MediawikiDao();
     $this->resource_restrictor = new MediawikiSiteAdminResourceRestrictor(new MediawikiSiteAdminResourceRestrictorDao(), ProjectManager::instance());
 }
 public function getDescriptionFieldsValue(Project $project)
 {
     $project_id = $project->getID();
     $description_fields_values = array();
     $results = $this->dao->getDescriptionFieldsValue($project_id);
     while ($row = $results->getRow()) {
         $description_fields_values[] = array('id' => $row['group_desc_id'], 'value' => $row['value']);
     }
     return $description_fields_values;
 }
 public function assertCommitMessageIsValid(Project $project, $commit_message)
 {
     if ($project->isSVNMandatoryRef()) {
         // Marvelous, extractCrossRef depends on globals group_id to find the group
         // when it's not explicit... yeah!
         $GLOBALS['group_id'] = $project->getID();
         if (!$this->reference_manager->stringContainsReferences($commit_message, $project)) {
             throw new Exception('Commit message must contains a reference');
         }
     }
 }
 /**
  * Creates the Umbrella Projects of a given project
  * @param Git_RemoteServer_GerritServer[] $gerrit_servers
  * @param Project $project
  */
 public function recursivelyCreateUmbrellaProjects(array $gerrit_servers, Project $project)
 {
     $parent_project = $this->project_manager->getParentProject($project->getID());
     $this->createProjectOnServers($gerrit_servers, $project);
     if (!$parent_project) {
         $this->resetProjectInheritanceOnServers($gerrit_servers, $project);
         return;
     }
     $this->recursivelyCreateUmbrellaProjects($gerrit_servers, $parent_project);
     $this->setProjectInheritanceOnServers($gerrit_servers, $project, $parent_project);
 }
 private function importContent(Project $project, $xml_contents, $extraction_path)
 {
     $project_id = $project->getID();
     $this->logger->info("Importing project in project {$project_id}");
     $this->checkFileIsValidXML($xml_contents);
     $xml_element = simplexml_load_string($xml_contents);
     $this->importUgroups($project, $xml_element);
     $this->logger->info("Ask to plugin to import data from XML");
     $this->event_manager->processEvent(Event::IMPORT_XML_PROJECT, array('project' => $project, 'xml_content' => $xml_element, 'extraction_path' => $extraction_path));
     $this->logger->info("Finish importing project in project {$project_id}");
 }
Example #19
0
 /**
  * Return all git repositories of a project (gitshell, gitolite, personal forks)
  *
  * @param Project $project
  *
  * @return Array of GitRepository
  */
 public function getAllRepositories(Project $project)
 {
     $repositories = array();
     $repository_list = $this->dao->getProjectRepositoryList($project->getID(), false, false);
     foreach ($repository_list as $row) {
         $repository = new GitRepository();
         $this->dao->hydrateRepositoryObject($repository, $row);
         $repositories[] = $repository;
     }
     return $repositories;
 }
 /**
  * @return Git_RemoteServer_GerritServer[]
  */
 public function getServersForProject(Project $project)
 {
     $servers = array();
     foreach ($this->dao->searchAllByProjectId($project->getID()) as $row) {
         $servers[$row['id']] = $this->instantiateFromRow($row);
     }
     foreach ($this->project_manager->getChildProjects($project->getID()) as $child) {
         // don't use array_merge, it will nuke the keys
         $servers = $servers + $this->getServersForProject($child);
     }
     return $servers;
 }
Example #21
0
 /**
  * Returns the group ID the release belongs to
  */
 function getGroupID()
 {
     if (!isset($this->group_id)) {
         if (isset($this->project)) {
             $this->group_id = $this->project->getID();
         } else {
             $package = $this->_getFRSPackageFactory()->getFRSPackageFromDb($this->getPackageID(), null, FRSPackageDao::INCLUDE_DELETED);
             $this->group_id = $package->getGroupID();
         }
     }
     return $this->group_id;
 }
Example #22
0
 /**
  * Get the HTML output for current binding
  *
  * @param Project $currentProject Project of the currently bound ugroup
  * @param ProjectUGroup  $currentSource  Currently bound ugroup
  *
  * @return String
  */
 private function getCurrentBindingHTML(Project $currentProject = null, ProjectUGroup $currentSource = null)
 {
     if ($currentSource) {
         $currentBindHTML = '';
         if ($currentSource && $currentProject->userIsAdmin()) {
             $currentBindHTML .= $GLOBALS['Language']->getText('project_ugroup_binding', 'current_binded', array('<a href="/project/admin/editugroup.php?group_id=' . $currentProject->getID() . '&ugroup_id=' . $currentSource->getId() . '&func=edit" ><b>' . $currentSource->getName() . '</b></a>', '<a href="/projects/' . $currentProject->getUnixName() . '" ><b>' . $currentProject->getPublicName() . '</b></a>'));
         }
         $currentBindHTML .= '<form action="" method="post"><input type="hidden" name="action" value="remove_binding" /><input type="submit" value="' . $GLOBALS['Language']->getText('project_ugroup_binding', 'remove_binding') . '"/></form>';
     } else {
         $currentBindHTML = $GLOBALS['Language']->getText('project_ugroup_binding', 'no_binding');
     }
     return $currentBindHTML;
 }
 /**
  * @param Project|string $project
  * @param MediawikiManager $mediawiki_manager
  * @param MediawikiLanguageManager $language_manager
  * @param MediawikiVersionManager $version_manager
  * @param MediawikiMLEBExtensionManager $mleb_manager
  */
 public function __construct(Project $project, MediawikiManager $mediawiki_manager, MediawikiLanguageManager $language_manager, MediawikiVersionManager $version_manager, MediawikiMLEBExtensionManager $mleb_manager)
 {
     $this->logger = new BackendLogger();
     $this->project = $project;
     $this->project_name = $project->getUnixName();
     $this->project_id = $project->getID();
     $this->dao = new MediawikiDao();
     $this->mediawiki_manager = $mediawiki_manager;
     $this->language_manager = $language_manager;
     $this->version_manager = $version_manager;
     $this->mleb_manager = $mleb_manager;
     $this->resource_restrictor = new MediawikiSiteAdminResourceRestrictor(new MediawikiSiteAdminResourceRestrictorDao(), ProjectManager::instance());
 }
 /**
  * @param Project $project
  *
  * @return string
  */
 public function getUsedLanguageForProject(Project $project)
 {
     $language = null;
     $result = $this->dao->getUsedLanguageForProject($project->getID());
     if (isset($result['language'])) {
         $language = $result['language'];
     } else {
         $available_languages = $this->getAvailableLanguages();
         if (count($available_languages) === 1) {
             $language = $available_languages[0];
             $this->saveLanguageOption($project, $language);
         }
     }
     return $language;
 }
Example #25
0
 private function import_notification(Project $project, $xml_svn)
 {
     $dao = $this->getNotificationDAO();
     $res = true;
     foreach ($xml_svn->notification as $notif) {
         $attrs = $notif->attributes();
         $path = $attrs['path'];
         $emails = $attrs['emails'];
         $ok = $dao->setSvnMailingList($project->getID(), $emails, $path);
         if (!$ok) {
             $res = false;
         }
     }
     return $res;
 }
 /**
  * Return a reference that match keyword and value
  * @param Project $project
  * @param String $keyword
  * @param String $value
  * @return Reference
  */
 public function getReference(Project $project, $keyword, $value)
 {
     $reference = false;
     list($repository_name, $sha1) = $this->splitRepositoryAndSha1($value);
     $repository = $this->repository_factory->getRepositoryByPath($project->getId(), $project->getUnixName() . '/' . $repository_name . '.git');
     if ($repository) {
         $args = array($repository->getId(), $sha1);
         $reference = $this->reference_manager->loadReferenceFromKeywordAndNumArgs($keyword, $project->getID(), count($args), $value);
         if ($reference) {
             $reference->setLink($reference->getLink() . '&p=' . $repository_name);
             $reference->replaceLink($args);
         }
     }
     return $reference;
 }
 /**
  * @param int $project_id
  * @param int $parent_project_id
  * @param Project|null $current_parent
  * @return boolean
  */
 private function validateParent($project_id, $parent_project_id, $current_parent)
 {
     if (!$current_parent && !$parent_project_id) {
         throw new Project_HierarchyManagerNoChangeException();
     }
     if ($current_parent && $current_parent->getID() === $parent_project_id) {
         throw new Project_HierarchyManagerNoChangeException();
     }
     $parents = $this->getAllParents($parent_project_id);
     if (in_array($project_id, $parents)) {
         throw new Project_HierarchyManagerAlreadyAncestorException();
     }
     if ($project_id == $parent_project_id) {
         throw new Project_HierarchyManagerAncestorIsSelfException();
     }
 }
Example #28
0
 public function __construct()
 {
     $this->config = $config = $this->getConfig();
     $this->have_pcntl = function_exists('pcntl_signal');
     // map project_id => channel(s)
     foreach ($config['channels'] as $proj => $chan) {
         $proj_id = Project::getID($proj);
         // we need to map old configs with just channels to new config with categories as well
         if (!is_array($chan)) {
             // old config, one channel
             $options = array($chan => array($config['default_category']));
         } elseif (isset($chan[0]) and !is_array($chan[0])) {
             // old config with multiple channels
             $options = array();
             foreach ($chan as $individual_chan) {
                 $options[$individual_chan] = array($config['default_category']);
             }
         } else {
             // new format
             $options = $chan;
         }
         $this->channels[$proj_id] = $options;
     }
 }
Example #29
0
 /**
  * Check if it is an update or delete to tags
  * @param String $path
  *
  * @return Boolean
  */
 private function isCommitDoneInImmutableTag(Project $project, $path)
 {
     $immutable_paths = explode(PHP_EOL, $this->handler->getImmutableTagsPathForProject($project->getID()));
     foreach ($immutable_paths as $immutable_path) {
         if ($this->isCommitForbidden($project, $immutable_path, $path)) {
             return true;
         }
     }
     return false;
 }
 /**
  * Update the http_domain and service when renaming the group
  * @param Project $project
  * @param String  $new_name
  * @return Boolean
  */
 public function renameProject($project, $new_name)
 {
     //Update 'groups' table
     $sql = ' UPDATE groups SET unix_group_name= ' . $this->da->quoteSmart($new_name) . ' , 
              http_domain=REPLACE (http_domain,' . $this->da->quoteSmart($project->getUnixName(false)) . ',' . $this->da->quoteSmart($new_name) . ')
              WHERE group_id= ' . $this->da->quoteSmart($project->getID());
     $res_groups = $this->update($sql);
     //Update 'service' table
     if ($res_groups) {
         $sql_summary = ' UPDATE service SET link= REPLACE (link,' . $this->da->quoteSmart($project->getUnixName()) . ',' . $this->da->quoteSmart(strtolower($new_name)) . ')
                           WHERE short_name="summary"
                           AND group_id= ' . $this->da->quoteSmart($project->getID());
         $res_summary = $this->update($sql_summary);
         if ($res_summary) {
             $sql_homePage = ' UPDATE service SET link= REPLACE (link,' . $this->da->quoteSmart($project->getUnixName()) . ',' . $this->da->quoteSmart(strtolower($new_name)) . ')
                               WHERE short_name="homepage"
                               AND group_id= ' . $this->da->quoteSmart($project->getID());
             return $this->update($sql_homePage);
         }
     }
     return false;
 }