Example #1
0
 /**
  * Writes the current references using a given opened xml writer
  *
  * @param xml_writer $xmlwriter
  */
 public function write_refs(xml_writer $xmlwriter) {
     $xmlwriter->begin_tag('inforef');
     foreach ($this->refs as $item => $ids) {
         $xmlwriter->begin_tag($item.'ref');
         foreach (array_keys($ids) as $id) {
             $xmlwriter->full_tag($item, $id);
         }
         $xmlwriter->end_tag($item.'ref');
     }
     $xmlwriter->end_tag('inforef');
 }
 /**
  * Writes the given XML tree data into the currently opened file
  *
  * @param string $element the name of the root element of the tree
  * @param array $data the associative array of data to write
  * @param array $attribs list of additional fields written as attributes instead of nested elements
  * @param string $parent used internally during the recursion, do not set yourself
  */
 protected function write_xml($element, array $data, array $attribs = array(), $parent = '/')
 {
     if (!$this->has_xml_writer()) {
         throw new moodle1_convert_exception('write_xml_without_writer');
     }
     $mypath = $parent . $element;
     $myattribs = array();
     // detect properties that should be rendered as element's attributes instead of children
     foreach ($data as $name => $value) {
         if (!is_array($value)) {
             if (in_array($mypath . '/' . $name, $attribs)) {
                 $myattribs[$name] = $value;
                 unset($data[$name]);
             }
         }
     }
     // reorder the $data so that all sub-branches are at the end (needed by our parser)
     $leaves = array();
     $branches = array();
     foreach ($data as $name => $value) {
         if (is_array($value)) {
             $branches[$name] = $value;
         } else {
             $leaves[$name] = $value;
         }
     }
     $data = array_merge($leaves, $branches);
     $this->xmlwriter->begin_tag($element, $myattribs);
     foreach ($data as $name => $value) {
         if (is_array($value)) {
             // recursively call self
             $this->write_xml($name, $value, $attribs, $mypath . '/');
         } else {
             $this->xmlwriter->full_tag($name, $value);
         }
     }
     $this->xmlwriter->end_tag($element);
 }
 /**
  * Copies the selected languages to the temp path
  *
  * @param xml_writer $xmlwriter The XML writer, by reference
  * @param string $path Where to store the data
  * @param array $ingredientsdata Ingredients to store
  */
 public function package_ingredients(&$xmlwriter, $path, $ingredientsdata)
 {
     global $CFG;
     if (!$ingredientsdata) {
         return false;
     }
     mkdir($path . '/' . $this->id, $CFG->directorypermissions);
     foreach ($ingredientsdata as $langid) {
         // External method to allow methods overwrite
         $langdirname = $this->get_lang_dir($langid);
         // All the languages are stored in dataroot, english is the only exception AFAIK
         $frompath = $this->langpath . '/' . $langdirname;
         // Recursive copy
         $topath = $path . '/' . $this->id . '/' . $langdirname;
         if (!$this->copy($frompath, $topath)) {
             debugging($frompath);
             debugging($topath);
             print_error('errorcopying', 'local_flavours');
         }
         $language = get_string_manager()->load_component_strings('langconfig', $langid);
         $xmlwriter->begin_tag($langid);
         $xmlwriter->full_tag('name', $language['thislanguage']);
         $xmlwriter->full_tag('path', $langid);
         $xmlwriter->end_tag($langid);
     }
     return true;
 }
Example #4
0
/**
 * Generate the mpr contents (xml files) in the temporal directory.
 *
 * @param array $runids list of runids to be generated.
 * @param string $tmpdir filesystem fullpath of tmp generation.
 * @return boolean the mpr contents have been generated (true) or no (false).
 */
function profiling_export_generate(array $runids, $tmpdir)
{
    global $CFG, $DB;
    // Calculate the header information to be sent to moodle_profiling_runs.xml.
    $release = $CFG->release;
    $version = $CFG->version;
    $dbtype = $CFG->dbtype;
    $githash = phpunit_util::get_git_hash();
    $date = time();
    // Create the xml output and writer for the main file.
    $mainxo = new file_xml_output($tmpdir . '/moodle_profiling_runs.xml');
    $mainxw = new xml_writer($mainxo);
    // Output begins.
    $mainxw->start();
    $mainxw->begin_tag('moodle_profiling_runs');
    // Send header information.
    $mainxw->begin_tag('info');
    $mainxw->full_tag('release', $release);
    $mainxw->full_tag('version', $version);
    $mainxw->full_tag('dbtype', $dbtype);
    if ($githash) {
        $mainxw->full_tag('githash', $githash);
    }
    $mainxw->full_tag('date', $date);
    $mainxw->end_tag('info');
    // Send information about runs.
    $mainxw->begin_tag('runs');
    foreach ($runids as $runid) {
        // Get the run information from DB.
        $run = $DB->get_record('profiling', array('runid' => $runid), '*', MUST_EXIST);
        $attributes = array('id' => $run->id, 'ref' => $run->runid . '.xml');
        $mainxw->full_tag('run', null, $attributes);
        // Create the individual run file.
        $runxo = new file_xml_output($tmpdir . '/' . $attributes['ref']);
        $runxw = new xml_writer($runxo);
        $runxw->start();
        $runxw->begin_tag('moodle_profiling_run');
        $runxw->full_tag('id', $run->id);
        $runxw->full_tag('runid', $run->runid);
        $runxw->full_tag('url', $run->url);
        $runxw->full_tag('runreference', $run->runreference);
        $runxw->full_tag('runcomment', $run->runcomment);
        $runxw->full_tag('timecreated', $run->timecreated);
        $runxw->full_tag('totalexecutiontime', $run->totalexecutiontime);
        $runxw->full_tag('totalcputime', $run->totalcputime);
        $runxw->full_tag('totalcalls', $run->totalcalls);
        $runxw->full_tag('totalmemory', $run->totalmemory);
        $runxw->full_tag('data', $run->data);
        $runxw->end_tag('moodle_profiling_run');
        $runxw->stop();
    }
    $mainxw->end_tag('runs');
    $mainxw->end_tag('moodle_profiling_runs');
    $mainxw->stop();
    return true;
}
 /**
  * Copies the selected plugins to the flavour file structure
  *
  * @param xml_writer $xmlwriter The XML writer, by reference
  * @param string $path Where to store the data
  * @param array $ingredientsdata Ingredients to store
  */
 public function package_ingredients(&$xmlwriter, $path, $ingredientsdata)
 {
     global $CFG;
     if (!$ingredientsdata) {
         return false;
     }
     // Required to find plugin types paths
     $plugintypesdata = get_plugin_types();
     // To find the plugins versions
     $pluginman = plugin_manager::instance();
     $systemplugins = $pluginman->get_plugins(true);
     mkdir($path . '/' . $this->id, $CFG->directorypermissions);
     // A first iteration to group ingredients by plugin type
     foreach ($ingredientsdata as $plugintype) {
         $tmparray = explode('/', $plugintype);
         $plugins[$tmparray[0]][$tmparray[1]] = $tmparray[1];
     }
     foreach ($plugins as $plugintype => $ingredients) {
         $xmlwriter->begin_tag($plugintype);
         // The plugin type folder
         $plugintypepath = $plugintypesdata[$plugintype];
         $plugintypebasepath = str_replace($CFG->dirroot, '', $plugintypepath);
         $plugintypeflavourpath = str_replace(rtrim($CFG->dirroot, '/'), $path . '/' . $this->id, $plugintypepath);
         // First condition to avoid subplugins conflicts
         if (!is_dir($plugintypeflavourpath)) {
             if (!mkdir($plugintypeflavourpath, $CFG->directorypermissions, true)) {
                 debugging($plugintypeflavourpath);
                 continue;
             }
         }
         foreach ($ingredients as $ingredient) {
             // Copying to the flavour filesystem
             $frompath = $plugintypepath . '/' . $ingredient;
             // Recursive copy
             $topath = $plugintypeflavourpath . '/' . $ingredient;
             if (!$this->copy($frompath, $topath)) {
                 debugging($frompath . '---' . $topath);
                 print_error('errorcopying', 'local_flavours');
             }
             // Adding the ingredient to the flavour data
             $xmlwriter->begin_tag($ingredient);
             $xmlwriter->full_tag('name', $this->get_system_plugin_visiblename($plugintype, $ingredient));
             $xmlwriter->full_tag('path', ltrim($plugintypebasepath, '/') . '/' . $ingredient);
             // The plugin version and required moodle version
             if (!empty($systemplugins[$plugintype][$ingredient]->versionrequires)) {
                 $requires = $systemplugins[$plugintype][$ingredient]->versionrequires;
             } else {
                 $requires = '';
             }
             if (!empty($systemplugins[$plugintype][$ingredient]->versiondisk)) {
                 $version = $systemplugins[$plugintype][$ingredient]->versiondisk;
             } else {
                 $version = '';
             }
             $xmlwriter->full_tag('versiondisk', $version);
             $xmlwriter->full_tag('requires', $requires);
             $xmlwriter->end_tag($ingredient);
         }
         $xmlwriter->end_tag($plugintype);
     }
     return true;
 }
$xml = new xml_writer($xml_output);
// Start the XML construction process
$xml->start();
// Open the top level XML element
$xml->begin_tag('MOODLE_ROLES_MIGRATION');
// General site and migration data
$xml->begin_tag('INFO');
$xml->full_tag('NAME', 'rolesmigration');
$xml->full_tag('MOODLE_VERSION', $CFG->version);
$xml->full_tag('MOODLE_RELEASE', $CFG->release);
$xml->full_tag('BACKUP_VERSION', $CFG->backup_version);
$xml->full_tag('BACKUP_RELEASE', $CFG->backup_release);
$xml->full_tag('DATE', time());
$xml->full_tag('ORIGINAL_WWWROOT', $CFG->wwwroot);
$xml->full_tag('ORIGINAL_SITE_IDENTIFIER_HASH', md5(get_site_identifier()));
$xml->end_tag('INFO');
// The roles tag contains all data for selected Roles on export screen
$xml->begin_tag('ROLES');
// Loop through provided role  IDs
foreach ($data->export as $role) {
    // Grab role from DB
    if ($role = $DB->get_record('role', array('shortname' => $role))) {
        $role_array = (array) $role;
        // Loop through columns and create tag for each one
        $xml->begin_tag('ROLE');
        foreach ($role_array as $field => $value) {
            $xml->full_tag(strtoupper($field), $value);
            // Lets make an array of Role IDs to use later while we're here
            if ('id' == $field) {
                $role_ids[] = $value;
            }
 /**
  * Writes the xml with the selected admin settings
  *
  * @param xml_writer $xmlwriter The XML writer, by reference
  * @param string $path Where to store the data
  * @param array $ingredientsdata Settings to store
  */
 public function package_ingredients(&$xmlwriter, $path, $ingredientsdata)
 {
     if (!$ingredientsdata) {
         return false;
     }
     $adminroot = admin_get_root();
     $this->get_branch_settings($adminroot->children, $this, true);
     foreach ($ingredientsdata as $settingspage) {
         // Settings page path
         $namespace = explode('/', $settingspage);
         // The admin settingspage is the last one
         $page = array_pop($namespace);
         if (!($settings = $this->get_settingspage_settings($namespace, $page, $this))) {
             continue;
         }
         $settingspagetagname = str_replace('/', '.', $settingspage);
         $xmlwriter->begin_tag($settingspagetagname);
         // Adding settings
         foreach ($settings as $setting) {
             // Getting the attributes of the tag
             // Some plugins has slashes, not availables as part of the tag name
             $attrs = array('plugin' => str_replace('/', '.', $setting->plugin));
             // Adding the extra values of the setting (if present) to the attributes array
             if (!empty($setting->attrs)) {
                 $attrs = array_merge($attrs, $setting->attrs);
                 $attrs['hasextra'] = '1';
             }
             $xmlwriter->full_tag($setting->name, $this->get_setting_value($setting->name, $setting->plugin), $attrs);
         }
         $xmlwriter->end_tag($settingspagetagname);
     }
     return true;
 }