示例#1
0
 public function importFromXML(Tracker $tracker, SimpleXMLElement $xml_element, $extraction_path, TrackerXmlFieldsMapping $xml_fields_mapping)
 {
     $this->rng_validator->validate($xml_element, realpath(dirname(TRACKER_BASE_DIR) . '/www/resources/artifacts.rng'));
     foreach ($xml_element->artifact as $artifact) {
         $this->importOneArtifactFromXML($tracker, $artifact, $extraction_path, $xml_fields_mapping);
     }
 }
示例#2
0
 /**
  *
  * @param SimpleXMLElement $xml_element
  * @param array $plannings
  *
  * @throws AgileDashboard_XMLExporterUnableToGetValueException
  */
 public function export(SimpleXMLElement $xml_element, array $plannings)
 {
     $agiledashboard_node = $xml_element->addChild(self::NODE_AGILEDASHBOARD);
     $plannings_node = $agiledashboard_node->addChild(self::NODE_PLANNINGS);
     foreach ($plannings as $planning) {
         /* @var $planning Planning */
         $planning_name = $planning->getName();
         $planning_title = $planning->getPlanTitle();
         $planning_tracker_id = $this->getFormattedTrackerId($planning->getPlanningTrackerId());
         $planning_backlog_title = $planning->getBacklogTitle();
         $this->checkString($planning_name, PlanningParameters::NAME);
         $this->checkString($planning_title, PlanningParameters::PLANNING_TITLE);
         $this->checkString($planning_backlog_title, PlanningParameters::BACKLOG_TITLE);
         $this->checkId($planning_tracker_id, PlanningParameters::PLANNING_TRACKER_ID);
         $planning_node = $plannings_node->addChild(self::NODE_PLANNING);
         $planning_node->addAttribute(PlanningParameters::NAME, $planning_name);
         $planning_node->addAttribute(PlanningParameters::PLANNING_TITLE, $planning_title);
         $planning_node->addAttribute(PlanningParameters::PLANNING_TRACKER_ID, $planning_tracker_id);
         $planning_node->addAttribute(PlanningParameters::BACKLOG_TITLE, $planning_backlog_title);
         $this->exportBacklogTrackers($planning_node, $planning);
         $this->exportPermissions($planning_node, $planning);
     }
     $rng_path = realpath(AGILEDASHBOARD_BASE_DIR . '/../www/resources/xml_project_agiledashboard.rng');
     $this->xml_validator->validate($agiledashboard_node, $rng_path);
 }
示例#3
0
 public function export(Tracker $tracker, SimpleXMLElement $xml_content, PFUser $user, ZipArchive $archive)
 {
     $artifacts_node = $xml_content->addChild('artifacts');
     $all_artifacts = $this->artifact_factory->getArtifactsByTrackerId($tracker->getId());
     $this->checkThreshold(count($all_artifacts));
     foreach ($all_artifacts as $artifact) {
         $artifact->exportToXML($artifacts_node, $user, $archive);
     }
     $this->rng_validator->validate($artifacts_node, realpath(dirname(TRACKER_BASE_DIR) . self::ARTIFACTS_RNG_PATH));
 }
 /**
  * Import cardwall ontop from XML input
  *
  * @param SimpleXMLElement $xml_input
  * @throws CardwallFromXmlImportCannotBeEnabledException
  */
 public function import(SimpleXMLElement $xml_input)
 {
     if (!$xml_input->{CardwallConfigXml::NODE_CARDWALL}) {
         return;
     }
     $rng_path = realpath(CARDWALL_BASE_DIR . '/../www/resources/xml_project_cardwall.rng');
     $this->xml_validator->validate($xml_input->{CardwallConfigXml::NODE_CARDWALL}, $rng_path);
     $this->importCardwalls($xml_input->{CardwallConfigXml::NODE_CARDWALL});
     $this->event_manager->processEvent(Event::IMPORT_XML_PROJECT_CARDWALL_DONE, array('project_id' => $this->group_id, 'xml_content' => $xml_input, 'mapping' => $this->mapping));
 }
 /**
  *
  * @param SimpleXMLElement $root
  * Export in XML the list of tracker with a cardwall
  */
 public function export(SimpleXMLElement $root)
 {
     $cardwall_node = $root->addChild(CardwallConfigXml::NODE_CARDWALL);
     $trackers_node = $cardwall_node->addChild(CardwallConfigXml::NODE_TRACKERS);
     $trackers = $this->tracker_factory->getTrackersByGroupId($this->project->getId());
     foreach ($trackers as $tracker) {
         $this->addTrackerChild($tracker, $trackers_node);
     }
     $rng_path = realpath(CARDWALL_BASE_DIR . '/../www/resources/xml_project_cardwall.rng');
     $this->xml_validator->validate($cardwall_node, $rng_path);
 }
示例#6
0
 public function exportSingleTrackerToXml(SimpleXMLElement $xml_content, $tracker_id, PFUser $user, ZipArchive $archive)
 {
     $xml_field_mapping = array();
     $xml_trackers = $xml_content->addChild('trackers');
     $tracker = $this->tracker_factory->getTrackerById($tracker_id);
     if ($tracker->isActive()) {
         $tracker_xml = $xml_trackers->addChild('tracker');
         $tracker->exportToXMLInProjectExportContext($tracker_xml, $xml_field_mapping);
         $this->artifact_xml_xport->export($tracker, $tracker_xml, $user, $archive);
     }
     $this->rng_validator->validate($xml_trackers, dirname(TRACKER_BASE_DIR) . '/www/resources/trackers.rng');
     return $xml_trackers;
 }
 public function import(Project $project, SimpleXMLElement $xml_input, $extraction_path)
 {
     $xml_svn = $xml_input->svn;
     if (!$xml_svn) {
         return true;
     }
     $rng_path = realpath(dirname(__FILE__) . '/../xml/resources/svn.rng');
     $this->xml_validator->validate($xml_svn, $rng_path);
     $this->logger->debug("XML tag <svn/> is valid");
     $this->importDumpFile($project, $xml_svn, $extraction_path);
     $this->importNotification($project, $xml_svn);
     $this->importAccessFile($project, $xml_svn);
 }
 /**
  * @param SimpleXMLElement $xml_element_ugroups
  *
  * @return array
  */
 private function getUgroupsFromXMLToAdd(Project $project, SimpleXMLElement $xml_element_ugroups)
 {
     $ugroups = array();
     $project_members = array();
     $rng_path = realpath(dirname(__FILE__) . '/../xml/resources/ugroups.rng');
     $this->xml_validator->validate($xml_element_ugroups, $rng_path);
     $this->logger->debug("XML Ugroups is valid");
     foreach ($xml_element_ugroups->ugroup as $ugroup) {
         $ugroup_name = (string) $ugroup['name'];
         $ugroup_description = (string) $ugroup['description'];
         $dynamic_ugroup_id = $this->ugroup_manager->getDynamicUGoupIdByName($ugroup_name);
         if ($this->ugroup_manager->getUGroupByName($project, $ugroup_name) && empty($dynamic_ugroup_id)) {
             $this->logger->debug("Ugroup {$ugroup_name} already exists in project -> skipped");
             continue;
         }
         $users = $this->getListOfUgroupMember($ugroup);
         if ($dynamic_ugroup_id == ProjectUGroup::PROJECT_MEMBERS) {
             $project_members = $users;
         } else {
             $ugroups[$ugroup_name]['name'] = $ugroup_name;
             $ugroups[$ugroup_name]['description'] = $ugroup_description;
             $ugroups[$ugroup_name]['users'] = $users;
         }
     }
     return array($ugroups, $project_members);
 }
 /**
  * Import one or multiple git repositories.
  * Returns true in case of success, false otherwise.
  * @var Project
  * @var SimpleXMLElement
  * @var String
  * @return boolean
  */
 public function import(Project $project, PFUser $creator, SimpleXMLElement $xml_input, $extraction_path)
 {
     $xml_git = $xml_input->git;
     if (!$xml_git) {
         $this->logger->debug('No git node found into xml.');
         return true;
     }
     $rng_path = realpath(dirname(__FILE__) . '/../../../src/common/xml/resources/git.rng');
     $this->xml_validator->validate($xml_git, $rng_path);
     $this->logger->debug("XML tag <git/> is valid");
     $this->logger->debug("Found {$xml_git->count()} repository(ies) to import.");
     foreach ($xml_git->children() as $repository) {
         $this->importRepository($project, $creator, $repository, $extraction_path);
     }
     return true;
 }
 /** @return string */
 public function toXML()
 {
     $xml_element = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>
                                          <users />');
     foreach ($this->users as $user) {
         if ($user->isNone()) {
             continue;
         }
         $user_node = $xml_element->addChild('user');
         $user_node->addChild('id', (int) $user->getId());
         $user_node->addChild('username', $user->getUserName());
         $this->cdata_factory->insert($user_node, 'realname', $user->getRealName());
         $this->cdata_factory->insert($user_node, 'email', $user->getEmail());
         $this->cdata_factory->insert($user_node, 'ldapid', $user->getLdapId());
     }
     $rng_path = realpath(ForgeConfig::get('tuleap_dir') . '/src/common/xml/resources/users.rng');
     $this->xml_validator->validate($xml_element, $rng_path);
     return $this->convertToXml($xml_element);
 }
 public function import()
 {
     $this->checkUserIsAdmin();
     $xml = $this->request->get('xml_content')->agiledashboard;
     $xml_validator = new XML_RNGValidator();
     $rng_path = realpath(AGILEDASHBOARD_BASE_DIR . '/../www/resources/xml_project_agiledashboard.rng');
     $xml_validator->validate($xml, $rng_path);
     $xml_importer = new AgileDashboard_XMLImporter();
     $data = $xml_importer->toArray($xml, $this->request->get('mapping'));
     $validator = new Planning_RequestValidator($this->planning_factory, $this->kanban_factory);
     foreach ($data['plannings'] as $planning) {
         $request_params = array('planning' => $planning, 'group_id' => $this->group_id, 'planning_id' => '');
         $request = new Codendi_Request($request_params);
         if ($validator->isValid($request)) {
             $this->planning_factory->createPlanning($this->group_id, PlanningParameters::fromArray($planning));
         } else {
             throw new Exception('Planning is not valid: ' . print_r($planning, true));
         }
     }
 }
 private function exportProjectUgroups(Project $project, SimpleXMLElement $into_xml)
 {
     $this->logger->debug("Exporting project's static ugroups");
     $ugroups = $this->ugroup_manager->getStaticUGroups($project);
     if (empty($ugroups)) {
         return;
     }
     $ugroups_node = $into_xml->addChild('ugroups');
     foreach ($ugroups as $ugroup) {
         $this->logger->debug("Current static ugroups: " . $ugroup->getName());
         $ugroup_node = $ugroups_node->addChild('ugroup');
         $ugroup_node->addAttribute('name', $ugroup->getNormalizedName());
         $ugroup_node->addAttribute('description', $ugroup->getDescription());
         $members_node = $ugroup_node->addChild('members');
         foreach ($ugroup->getMembers() as $member) {
             $this->user_xml_exporter->exportUser($member, $members_node, 'member');
         }
     }
     $rng_path = realpath(dirname(__FILE__) . '/../xml/resources/ugroups.rng');
     $this->xml_validator->validate($ugroups_node, $rng_path);
 }
 /**
  * First, creates a new Tracker Object by importing its structure from an XML file,
  * then, imports it into the Database, before verifying the consistency
  *
  * @param string         $xml_element        the location of the imported file
  * @param int            $groupId        the Id of the project to create the tracker
  * @param string         $name           the name of the tracker (label)
  * @param string         $description    the description of the tracker
  * @param string         $itemname       the short name of the tracker
  *
  * @throws TrackerFromXmlException
  * @return the new Tracker, or null if error
  */
 public function createFromXML(SimpleXMLElement $xml_element, $groupId, $name, $description, $itemname)
 {
     $tracker = null;
     if ($this->tracker_factory->validMandatoryInfoOnCreate($name, $description, $itemname, $groupId)) {
         $this->rng_validator->validate($xml_element, realpath(dirname(TRACKER_BASE_DIR) . '/www/resources/tracker.rng'));
         $tracker = $this->getInstanceFromXML($xml_element, $groupId, $name, $description, $itemname);
         //Testing consistency of the imported tracker before updating database
         if ($tracker->testImport()) {
             if ($tracker_id = $this->tracker_factory->saveObject($tracker)) {
                 $tracker->setId($tracker_id);
             } else {
                 throw new TrackerFromXmlException($GLOBALS['Language']->getText('plugin_tracker_admin', 'error_during_creation'));
             }
         } else {
             throw new TrackerFromXmlException('XML file cannot be imported');
         }
     }
     return $tracker;
 }
 private function fromXML(SimpleXMLElement $xml, $template_id, XML_RNGValidator $xml_validator = null, ServiceManager $service_manager = null, ProjectManager $project_manager = null)
 {
     if (empty($xml_validator)) {
         $xml_validator = new XML_RNGValidator();
     }
     if (empty($service_manager)) {
         $service_manager = ServiceManager::instance();
     }
     if (empty($project_manager)) {
         $project_manager = ProjectManager::instance();
     }
     $rng_path = realpath(dirname(__FILE__) . '/../xml/resources/project/project.rng');
     $xml_validator->validate($xml, $rng_path);
     $long_description_tagname = 'long-description';
     $attrs = $xml->attributes();
     $this->unix_name = (string) $attrs['unix-name'];
     $this->full_name = (string) $attrs['full-name'];
     $this->short_description = (string) $attrs['description'];
     $this->built_from_template = (int) $template_id;
     $this->is_test = (bool) false;
     $this->is_public = null;
     $this->trove_data = array();
     $this->data_services = array();
     $this->data_fields = array('form_101' => $xml->{$long_description_tagname});
     if ($attrs['access'] == 'public') {
         $this->is_public = true;
     } else {
         if ($attrs['access'] == 'private') {
             $this->is_public = false;
         }
     }
     $this->markUsedServicesFromXML($xml, $template_id, $service_manager, $project_manager);
 }
}
try {
    $xml = new DOMDocument("1.0", "UTF8");
    $logger = new Log_ConsoleLogger();
    $archive = new ZipArchive();
    if ($archive->open($archive_path, ZipArchive::CREATE) !== true) {
        echo '*** ERROR: Cannot create archive: ' . $archive_path;
        exit(1);
    }
    $dao = new ArtifactXMLExporterDao();
    $node_helper = new ArtifactXMLNodeHelper($xml);
    $attachment_exporter = new ArtifactAttachmentXMLZipper($node_helper, $dao, $archive, $debug);
    $exporter = new ArtifactXMLExporter($dao, $attachment_exporter, $node_helper, $logger);
    $exporter->exportTrackerData($atid);
    if (!$debug) {
        $validator = new XML_RNGValidator();
        $validator->validate(simplexml_import_dom($xml), realpath(dirname(TRACKER_BASE_DIR) . '/www/resources/artifacts.rng'));
    }
    $xml_security = new XML_Security();
    $xml_security->enableExternalLoadOfEntities();
    $xsl = new DOMDocument();
    $xsl->load(dirname(__FILE__) . '/xml/indent.xsl');
    $proc = new XSLTProcessor();
    $proc->importStyleSheet($xsl);
    $archive->addFromString('artifacts.xml', $proc->transformToXML($xml));
    $xml_security->disableExternalLoadOfEntities();
    $archive->close();
} catch (XML_ParseException $exception) {
    foreach ($exception->getErrors() as $error) {
        echo $error . PHP_EOL;
    }