Moosh\Command\Moodle26\Category\CategoryImport::execute PHP Method

execute() public method

public execute ( )
    public function execute()
    {
        global $CFG;
        require_once $CFG->dirroot . '/course/lib.php';
        $options = $this->expandedOptions;
        $arguments = $this->arguments;
        $file = $this->checkFileArg($arguments[0]);
        $this->categorystack = array();
        if ($options['parent']) {
            $this->categorystack[] = $options['parent'];
        } else {
            $this->categorystack[] = 0;
        }
        $this->coursesmap = array();
        $this->parser = xml_parser_create();
        xml_set_element_handler($this->parser, array(&$this, "start_element"), array(&$this, "end_element"));
        if (!($fp = fopen($file, "r"))) {
            die("could not open XML input");
        }
        while ($data = fread($fp, 4096)) {
            if (!xml_parse($this->parser, $data, feof($fp))) {
                die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)));
            }
        }
        xml_parser_free($this->parser);
        fix_course_sortorder();
    }