Do the job.
@return competency_framework
422768
public function import() {
        $record = clone $this->framework;
        unset($record->children);

        $record->scaleid = $this->get_scale_id($record->scalevalues, $record->shortname);
        $record->scaleconfiguration = $this->get_scale_configuration($record->scaleid, $record->scaleconfiguration);
        unset($record->scalevalues);
        $record->contextid = context_system::instance()->id;

        $framework = api::create_framework($record);
        if ($this->useprogressbar === true) {
            $this->progress = new \core\progress\display_if_slow(get_string('importingfile', 'tool_lpimportcsv'));
        } else {
            $this->progress = new \core\progress\none();
        }

        $this->progress->start_progress('', (count($this->framework->children) * 2));
        raise_memory_limit(MEMORY_EXTRA);
        // Now all the children.
        foreach ($this->framework->children as $comp) {
            $this->progress->increment_progress();
            $this->create_competency($comp, null, $framework);
        }

        // Now create the rules.
        foreach ($this->framework->children as $record) {
            $this->progress->increment_progress();
            $this->set_rules($record);
            $this->set_related($record);
        }
        $this->progress->end_progress();

        $this->importer->cleanup();
        return $framework;
    }
1242863
protected function doExecute()
    {
        if ($this->io->getOption('h')) {
            return $this->help();
        }

        $this->tag = $tag = $this->io->getOption('t') ?: $this->io->getOption('tag');

        $branch = $this->io->getOption('b') ?: $this->io->getOption('branch', 'test');

        $force = $this->io->getOption('f') ?: $this->io->getOption('force', false);

        $force = $force ? ' -f' : false;

        if ($this->tag && !$this->io->getOption('no-replace')) {
            $this->replaceDocblockTags();
        }

        $this->branch = $branch;

        $this->exec('git fetch origin');

        $this->exec('git branch -D ' . $branch);

        $this->exec('git checkout -b ' . $branch);

        $this->exec('git merge master');

        if ($this->tag) {
            $this->exec('git tag -d ' . $tag);

            $this->exec('git push origin :refs/tags/' . $tag);

            $this->exec('git tag ' . $tag);

            $this->exec(sprintf('git push origin %s' . $force, $this->tag));
        }

        $this->exec(sprintf('git push origin %s %s:%s master:master' . $force, $tag, $branch, $branch));

        $allows = $this->io->getArguments();

        foreach ($this->subtrees as $subtree => $namespace) {
            if ($allows && !in_array($subtree, $allows)) {
                continue;
            }

            $this->splitTree($subtree, $namespace);
        }

        $this->exec('git checkout master');

        $this->out()->out('Split finish.');

        return true;
    }
255538
public function get_context_from_competency(competency $competency) {
        $frameworkid = $competency->get('competencyframeworkid');
        if (!isset($this->frameworkscontexts[$frameworkid])) {
            $framework = $this->get_framework_from_competency($competency);
            $this->frameworkscontexts[$frameworkid] = $framework->get_context();
        }
        return $this->frameworkscontexts[$frameworkid];
    }
602608
public function execute() {
        global $CFG, $DB;

        $sql = "SELECT w.*
                  FROM {workshopallocation_scheduled} a
                  JOIN {workshop} w ON a.workshopid = w.id
                 WHERE a.enabled = 1
                   AND w.phase = 20
                   AND w.submissionend > 0
                   AND w.submissionend < ?
                   AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)";
        $workshops = $DB->get_records_sql($sql, array(time()));

        if (empty($workshops)) {
            mtrace('... no workshops awaiting scheduled allocation. ', '');
            return;
        }

        mtrace('... executing scheduled allocation in ' . count($workshops) . ' workshop(s) ... ', '');

        require_once($CFG->dirroot . '/mod/workshop/locallib.php');

        foreach ($workshops as $workshop) {
            $cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course, false, MUST_EXIST);
            $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
            $workshop = new \workshop($workshop, $cm, $course);
            $allocator = $workshop->allocator_instance('scheduled');
            $allocator->execute();
        }
    }
292566
public function perform()
	{
		$this->guardAgainstImpossibleMove();

		if ( $this->fireMoveEvent( 'moving' ) === false )
			return $this->model;

		if ( $this->hasChange() )
		{
			$self = $this;

			$this->model->getConnection()->transaction( function () use ( $self )
			{
				$self->updateStructure();
			} );

			$this->target->reload();

			$this->model->setDepthWithSubtree();

			$this->model->reload();
		}

		$this->fireMoveEvent( 'moved', false );

		return $this->model;
	}
322064
public function export() {
        global $CFG;
        require_once($CFG->libdir . '/csvlib.class.php');

        $writer = new csv_export_writer();
        $filename = clean_param($this->framework->get('shortname') . '-' . $this->framework->get('idnumber'), PARAM_FILE);
        $writer->set_filename($filename);

        $headers = framework_importer::list_required_headers();

        $writer->add_data($headers);

        // Order and number of columns must match framework_importer::list_required_headers().
        $row = array(
            '',
            $this->framework->get('idnumber'),
            $this->framework->get('shortname'),
            $this->framework->get('description'),
            $this->framework->get('descriptionformat'),
            $this->framework->get_scale()->compact_items(),
            $this->framework->get('scaleconfiguration'),
            '',
            '',
            '',
            '',
            '',
            true,
            implode(',', $this->framework->get('taxonomies'))
        );
        $writer->add_data($row);

        $filters = array('competencyframeworkid' => $this->framework->get('id'));
        $competencies = api::list_competencies($filters);
        // Index by id so we can lookup parents.
        $indexed = array();
        foreach ($competencies as $competency) {
            $indexed[$competency->get('id')] = $competency;
        }
        foreach ($competencies as $competency) {
            $parentidnumber = '';
            if ($competency->get('parentid') > 0) {
                $parent = $indexed[$competency->get('parentid')];
                $parentidnumber = $parent->get('idnumber');
            }

            $scalevalues = '';
            $scaleconfig = '';
            if ($competency->get('scaleid') !== null) {
                $scalevalues = $competency->get_scale()->compact_items();
                $scaleconfig = $competency->get('scaleconfiguration');
            }

            $ruleconfig = $competency->get('ruleconfig');
            if ($ruleconfig === null) {
                $ruleconfig = "null";
            }

            $allrelated = $competency->get_related_competencies();

            $relatedidnumbers = array();
            foreach ($allrelated as $onerelated) {
                $relatedidnumbers[] = str_replace(',', '%2C', $onerelated->get('idnumber'));
            }
            $relatedidnumbers = implode(',', $relatedidnumbers);

            // Order and number of columns must match framework_importer::list_required_headers().
            $row = array(
                $parentidnumber,
                $competency->get('idnumber'),
                $competency->get('shortname'),
                $competency->get('description'),
                $competency->get('descriptionformat'),
                $scalevalues,
                $scaleconfig,
                $competency->get('ruletype'),
                $competency->get('ruleoutcome'),
                $ruleconfig,
                $relatedidnumbers,
                $competency->get('id'),
                false,
                ''
            );

            $writer->add_data($row);
        }

        $writer->download_file();
    }
1014136
public function get_framework_from_competency(competency $competency) {
        $frameworkid = $competency->get('competencyframeworkid');
        if (!isset($this->frameworks[$frameworkid])) {
            $this->frameworks[$frameworkid] = $competency->get_framework();
        }
        return $this->frameworks[$frameworkid];
    }
431640
public function build() {

        // Define the task contextid (the course one)
        $this->contextid = context_course::instance($this->get_courseid())->id;

        // Executed conditionally if restoring to new course or if overwrite_conf setting is enabled
        if ($this->get_target() == backup::TARGET_NEW_COURSE || $this->get_setting_value('overwrite_conf') == true) {
            $this->add_step(new restore_course_structure_step('course_info', 'course.xml'));

            // Search reindexing (if enabled).
            if (\core_search\manager::is_indexing_enabled()) {
                $this->add_step(new restore_course_search_index('course_search_index'));
            }
        }

        $this->add_step(new restore_course_legacy_files_step('legacy_files'));

        // Deal with enrolment methods and user enrolments.
        if ($this->plan->get_mode() == backup::MODE_IMPORT) {
            // No need to do anything with enrolments.

        } else if (!$this->get_setting_value('users') or $this->plan->get_mode() == backup::MODE_HUB) {
            if ($this->get_setting_value('enrolments') == backup::ENROL_ALWAYS && $this->plan->get_mode() != backup::MODE_HUB) {
                // Restore enrolment methods.
                $this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
            } else if ($this->get_target() == backup::TARGET_CURRENT_ADDING or $this->get_target() == backup::TARGET_EXISTING_ADDING) {
                // Keep current enrolments unchanged.
            } else {
                // If no instances yet add default enrol methods the same way as when creating new course in UI.
                $this->add_step(new restore_default_enrolments_step('default_enrolments'));
            }

        } else {
            // Restore course enrolment data.
            $this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
        }

        // Populate groups, this must be done after enrolments because only enrolled users may be in groups.
        $this->add_step(new restore_groups_members_structure_step('create_groups_members', '../groups.xml'));

        // Restore course role assignments and overrides (internally will observe the role_assignments setting),
        // this must be done after all users are enrolled.
        $this->add_step(new restore_ras_and_caps_structure_step('course_ras_and_caps', 'roles.xml'));

        // Restore course filters (conditionally)
        if ($this->get_setting_value('filters')) {
            $this->add_step(new restore_filters_structure_step('course_filters', 'filters.xml'));
        }

        // Restore course comments (conditionally)
        if ($this->get_setting_value('comments')) {
            $this->add_step(new restore_comments_structure_step('course_comments', 'comments.xml'));
        }

        // Calendar events (conditionally)
        if ($this->get_setting_value('calendarevents')) {
            $this->add_step(new restore_calendarevents_structure_step('course_calendar', 'calendar.xml'));
        }

        // Course competencies.
        $this->add_step(new restore_course_competencies_structure_step('course_competencies', 'competencies.xml'));

        // Activity completion defaults.
        $this->add_step(new restore_completion_defaults_structure_step('course_completion_defaults', 'completiondefaults.xml'));

        // At the end, mark it as built
        $this->built = true;
    }
1201095
public function execute()
    {

        $message = $this->phpci->interpolate($this->message);
        $successfulBuild = $this->build->isSuccessful() ? 'Success' : 'Failed';
        $push = new Push($this->api_key);
        $flowMessage = TeamInboxMessage::create()
            ->setSource("PHPCI")
            ->setFromAddress($this->email)
            ->setFromName($this->build->getProject()->getTitle())
            ->setSubject($successfulBuild)
            ->setTags(['#ci'])
            ->setLink($this->build->getBranchLink())
            ->setContent($message);

        if (!$push->sendTeamInboxMessage($flowMessage, array('connect_timeout' => 5000, 'timeout' => 5000))) {
            throw new \Exception(sprintf('Flowdock Failed: %s', $flowMessage->getResponseErrors()));
        }
        return true;
    }
1019657
public function handle()
    {
        if (!file_exists(base_path('.env'))) {
            $this->error('File .env not found');
            return false;
        }
        if (config('app.key') == '') {
            $this->info('Key Generate...');
            $this->call('key:generate');
        }
        if (!is_link(public_path('storage'))) {
            $this->info('Storage Link...');
            $this->call('storage:link');
        }
        if (!file_exists(app_path('Http/Controllers/HomeController.php')) && $this->confirm('Do you want to run make:auth?')) {
            $this->info('Make Auth...');
            $this->call('make:auth');
        }
        $this->info('Migrate and Seeding...');
        if ($this->option('migrate-fresh')) {
            $this->call('migrate:fresh', [ '--seed' => true ]);
        } elseif ($this->option('migrate-refresh')) {
            $this->call('migrate:refresh', [ '--seed' => true ]);
        } else {
            $this->call('migrate', [ '--seed' => true ]);
        }
        if (!file_exists(storage_path('oauth-private.key')) || !file_exists(storage_path('oauth-public.key'))) {
            $this->info('Passport Key Generate...');
            $this->call('passport:install');
        }

        return true;
    }
564609
public function execute()
    {
        $curdir = getcwd();
        chdir($this->phpci->buildPath);

        $phpspec = $this->phpci->findBinary(array('phpspec', 'phpspec.php'));

        $success = $this->phpci->executeCommand($phpspec . ' --format=junit --no-code-generation run');
        $output = $this->phpci->getLastOutput();

        chdir($curdir);

        /*
         * process xml output
         *
         * <testsuites time=FLOAT tests=INT failures=INT errors=INT>
         *   <testsuite name=STRING time=FLOAT tests=INT failures=INT errors=INT skipped=INT>
         *     <testcase name=STRING time=FLOAT classname=STRING status=STRING/>
         *   </testsuite>
         * </testsuites
         */

        $xml = new \SimpleXMLElement($output);
        $attr = $xml->attributes();
        $data = array(
            'time' => (float)$attr['time'],
            'tests' => (int)$attr['tests'],
            'failures' => (int)$attr['failures'],
            'errors' => (int)$attr['errors'],

            // now all the tests
            'suites' => array()
        );

        /**
         * @var \SimpleXMLElement $group
         */
        foreach ($xml->xpath('testsuite') as $group) {
            $attr = $group->attributes();
            $suite = array(
                'name' => (String)$attr['name'],
                'time' => (float)$attr['time'],
                'tests' => (int)$attr['tests'],
                'failures' => (int)$attr['failures'],
                'errors' => (int)$attr['errors'],
                'skipped' => (int)$attr['skipped'],

                // now the cases
                'cases' => array()
            );

            /**
             * @var \SimpleXMLElement $child
             */
            foreach ($group->xpath('testcase') as $child) {
                $attr = $child->attributes();
                $case = array(
                    'name' => (String)$attr['name'],
                    'classname' => (String)$attr['classname'],
                    'time' => (float)$attr['time'],
                    'status' => (String)$attr['status'],
                );

                if ($case['status']=='failed') {
                    $error = array();
                    /*
                     * ok, sad, we had an error
                     *
                     * there should be one - foreach makes this easier
                     */
                    foreach ($child->xpath('failure') as $failure) {
                        $attr = $failure->attributes();
                        $error['type'] = (String)$attr['type'];
                        $error['message'] = (String)$attr['message'];
                    }

                    foreach ($child->xpath('system-err') as $system_err) {
                        $error['raw'] = (String)$system_err;
                    }

                    $case['error'] = $error;
                }

                $suite['cases'][] = $case;
            }

            $data['suites'][] = $suite;
        }

        $this->build->storeMeta('phpspec', $data);


        return $success;
    }
642495
public function execute()
    {
        if ($this->order !== null) {
            $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Orders::PATH, $this->order->getId(), self::PATH);
        } else {
            $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Multiorders::PATH, $this->multiorder->getId(), self::MULTI_PAYMENTS_PATH);
        }

        $response = $this->httpRequest($path, Requests::POST, $this);

        return $this->populate($response);
    }
684292
public function executeJob()
    {
        $this->markStarted();
        try {
            $resultMsg = $this->run();
            if (strlen($resultMsg) == 0) {
                $resultMsg = t('The Job was run successfully.');
            }
            $error = static::JOB_SUCCESS;
        } catch (\Exception $e) {
            $resultMsg = $e->getMessage();
            $error = static::JOB_ERROR_EXCEPTION_GENERAL;
        }

        $je = new Event($this);
        Events::dispatch('on_job_execute', $je);

        $obj = $this->markCompleted($error, $resultMsg);

        return $obj;
    }
766979
public function handle()
    {
        $name = $this->argument('name');
        $createMigration = $this->option('m');
        $createResourceController = $this->option('c');

        if (empty($name)) {
            return $this->error("You need to specify an object to create");
        }

        $newObject = ucfirst($name).'.php';
        $newContract = ucfirst($name).'Repository.php';
        $newConcrete = 'Eloquent'.ucfirst($name).'Repository.php';

        $this->createObjectFiles($name, $newObject, $newContract, $newConcrete);

        $this->makeBindings($newContract, $newConcrete);

        $this->makeMigration($createMigration);

        $this->makeResourceController($createResourceController);

        return $this->info('Your structure has been created');
    }
655390
public static final function create_from_framework(competency_framework $framework) {
        if (!$framework->get('id')) {
            throw new \coding_exception('The competency framework ID must be set.');
        }
        $event = static::create(array(
            'contextid'  => $framework->get('contextid'),
            'objectid' => $framework->get('id')
        ));
        $event->add_record_snapshot(competency_framework::TABLE, $framework->to_record());
        return $event;
    }
1128541
public function execute() {
        global $CFG;

        require_once($CFG->dirroot . '/enrol/flatfile/lib.php');

        if (!enrol_is_enabled('flatfile')) {
            return;
        }

        // Instance of enrol_flatfile_plugin.
        $plugin = enrol_get_plugin('flatfile');
        $result = $plugin->sync(new \null_progress_trace());
        return $result;

    }
575076
public function execute()
    {
        $success = false;

        try {
            $file = $this->getDirectory() . DIRECTORY_SEPARATOR . $this->getFilename();
            $phar = new PHPPhar($file, 0, $this->getFilename());
            $phar->buildFromDirectory($this->getPHPCI()->buildPath, $this->getRegExp());

            $stub = $this->getStubContent();
            if ($stub) {
                $phar->setStub($stub);
            }

            $success = true;
        } catch (Exception $e) {
            $this->getPHPCI()->log(Lang::get('phar_internal_error'));
            $this->getPHPCI()->log($e->getMessage());
        }

        return $success;
    }