Processing functions go here

@global moodledatabase $DB
@param stdClass $data
326878
public function process_course($data) {
        global $CFG, $DB;
        $context = context::instance_by_id($this->task->get_contextid());
        $userid = $this->task->get_userid();
        $target = $this->get_task()->get_target();
        $isnewcourse = $target == backup::TARGET_NEW_COURSE;

        // When restoring to a new course we can set all the things except for the ID number.
        $canchangeidnumber = $isnewcourse || has_capability('moodle/course:changeidnumber', $context, $userid);
        $canchangesummary = $isnewcourse || has_capability('moodle/course:changesummary', $context, $userid);
        $canforcelanguage = has_capability('moodle/course:setforcedlanguage', $context, $userid);

        $data = (object)$data;
        $data->id = $this->get_courseid();

        // Calculate final course names, to avoid dupes.
        $fullname  = $this->get_setting_value('course_fullname');
        $shortname = $this->get_setting_value('course_shortname');
        list($data->fullname, $data->shortname) = restore_dbops::calculate_course_names($this->get_courseid(),
            $fullname === false ? $data->fullname : $fullname,
            $shortname === false ? $data->shortname : $shortname);
        // Do not modify the course names at all when merging and user selected to keep the names (or prohibited by cap).
        if (!$isnewcourse && $fullname === false) {
            unset($data->fullname);
        }
        if (!$isnewcourse && $shortname === false) {
            unset($data->shortname);
        }

        // Unset summary if user can't change it.
        if (!$canchangesummary) {
            unset($data->summary);
            unset($data->summaryformat);
        }

        // Unset lang if user can't change it.
        if (!$canforcelanguage) {
            unset($data->lang);
        }

        // Only allow the idnumber to be set if the user has permission and the idnumber is not already in use by
        // another course on this site.
        if (!empty($data->idnumber) && $canchangeidnumber && $this->task->is_samesite()
                && !$DB->record_exists('course', array('idnumber' => $data->idnumber))) {
            // Do not reset idnumber.

        } else if (!$isnewcourse) {
            // Prevent override when restoring as merge.
            unset($data->idnumber);

        } else {
            $data->idnumber = '';
        }

        // Any empty value for course->hiddensections will lead to 0 (default, show collapsed).
        // It has been reported that some old 1.9 courses may have it null leading to DB error. MDL-31532
        if (empty($data->hiddensections)) {
            $data->hiddensections = 0;
        }

        // Set legacyrestrictmodules to true if the course was resticting modules. If so
        // then we will need to process restricted modules after execution.
        $this->legacyrestrictmodules = !empty($data->restrictmodules);

        $data->startdate= $this->apply_date_offset($data->startdate);
        if (isset($data->enddate)) {
            $data->enddate = $this->apply_date_offset($data->enddate);
        }

        if ($data->defaultgroupingid) {
            $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid);
        }
        if (empty($CFG->enablecompletion)) {
            $data->enablecompletion = 0;
            $data->completionstartonenrol = 0;
            $data->completionnotify = 0;
        }
        $languages = get_string_manager()->get_list_of_translations(); // Get languages for quick search
        if (isset($data->lang) && !array_key_exists($data->lang, $languages)) {
            $data->lang = '';
        }

        $themes = get_list_of_themes(); // Get themes for quick search later
        if (!array_key_exists($data->theme, $themes) || empty($CFG->allowcoursethemes)) {
            $data->theme = '';
        }

        // Check if this is an old SCORM course format.
        if ($data->format == 'scorm') {
            $data->format = 'singleactivity';
            $data->activitytype = 'scorm';
        }

        // Course record ready, update it
        $DB->update_record('course', $data);

        course_get_format($data)->update_course_format_options($data);

        // Role name aliases
        restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid());
    }
606327
protected function initialize()
    {
        $this->data = new stdClass();
        $this->data->transferInstrument = new stdClass();
        $this->data->transferInstrument->bankAccount = new stdClass();
        $this->data->transferInstrument->bankAccount->holder = new stdClass();
        $this->data->transferInstrument->bankAccount->holder->taxDocument = new stdClass();
    }
1216108
public function init(\stdClass $initData = null)
    {
        if ($initData === null) {
            $this->connection->connect();
        } else {
            $this->openConnection($initData);
        }
    }
465188
function process(){
		LogMaster::log("DataProcessor object initialized",$_POST);
		
		$results=array();

		$ids=$this->get_ids();
		$rows_data=$this->get_post_values($ids);
		$failed=false;
		
		try{
			if ($this->connector->sql->is_global_transaction())
				$this->connector->sql->begin_transaction();
			
			for ($i=0; $i < sizeof($ids); $i++) { 
				$rid = $ids[$i];
				LogMaster::log("Row data [{$rid}]",$rows_data[$rid]);
				$status = $this->get_operation($rid);
				
				$action=new DataAction($status,$rid,$rows_data[$rid]);
				$results[]=$action;
				$this->inner_process($action);
			}
			
		} catch(Exception $e){
			LogMaster::log($e);
			$failed=true;
		}
		
		if ($this->connector->sql->is_global_transaction()){
			if (!$failed)
				for ($i=0; $i < sizeof($results); $i++)
					if ($results[$i]->get_status()=="error" || $results[$i]->get_status()=="invalid"){
						$failed=true; 
						break;
					}
			if ($failed){
				for ($i=0; $i < sizeof($results); $i++)
					$results[$i]->error();
				$this->connector->sql->rollback_transaction();
			}
			else
				$this->connector->sql->commit_transaction();
		}
		
		$this->output_as_xml($results);
	}
925355
public function populate(\stdClass $data)
    {
        $this->CodEmpresa = $data->codEmpresa;
        $this->CodIntegracaoContaCorrente = $data->codIntegracaoContaCorrente;
        $this->CodTipoMovto = $data->codTipoMovto;
        $this->DatMovimento = $data->datMovimento;
        $this->VlrMovimento = $data->vlrMovimento;
        $this->DscComplemento = $data->dscComplemento;
        $this->CodIntegracaoTipoMovtoCc = $data->codIntegracaoTipoMovtoCc;
        $this->CodIntegracaoMovtoCc = $data->codIntegracaoMovtoCc;
        $this->CodIntegracaoFilial = $data->codIntegracaoFilial;
    }
130862
private function execute(stdClass $data = null, $resourceId = null)
    {
        $body = empty($data) ? new stdClass() : $data;
        $response = $this->httpRequest($this->getPath($resourceId), Requests::POST, $body);

        return $this->populate($response);
    }
100538
public function process_gradingform_rubric_level($data) {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id;
        $data->criterionid = $this->get_new_parentid('gradingform_rubric_criterion');

        $newid = $DB->insert_record('gradingform_rubric_levels', $data);
        $this->set_mapping('gradingform_rubric_level', $oldid, $newid);
    }
1135277
public function execute(NodeData $node)
    {
        $nodeType = $this->nodeTypeManager->getNodeType($this->newType);
        $node->setNodeType($nodeType);
    }
366876
public function process_assignment($data) {
        global $DB;

        $data = (object)$data;

        // Check roleid, userid are one of the mapped ones
        if (!$newroleid = $this->get_mappingid('role', $data->roleid)) {
            return;
        }
        if (!$newuserid = $this->get_mappingid('user', $data->userid)) {
            return;
        }
        if (!$DB->record_exists('user', array('id' => $newuserid, 'deleted' => 0))) {
            // Only assign roles to not deleted users
            return;
        }
        if (!$contextid = $this->task->get_contextid()) {
            return;
        }

        if (empty($data->component)) {
            // assign standard manual roles
            // TODO: role_assign() needs one userid param to be able to specify our restore userid
            role_assign($newroleid, $newuserid, $contextid);

        } else if ((strpos($data->component, 'enrol_') === 0)) {
            // Deal with enrolment roles - ignore the component and just find out the instance via new id,
            // it is possible that enrolment was restored using different plugin type.
            if (!isset($this->plugins)) {
                $this->plugins = enrol_get_plugins(true);
            }
            if ($enrolid = $this->get_mappingid('enrol', $data->itemid)) {
                if ($instance = $DB->get_record('enrol', array('id'=>$enrolid))) {
                    if (isset($this->plugins[$instance->enrol])) {
                        $this->plugins[$instance->enrol]->restore_role_assignment($instance, $newroleid, $newuserid, $contextid);
                    }
                }
            }

        } else {
            $data->roleid    = $newroleid;
            $data->userid    = $newuserid;
            $data->contextid = $contextid;
            $dir = core_component::get_component_directory($data->component);
            if ($dir and is_dir($dir)) {
                if (component_callback($data->component, 'restore_role_assignment', array($this, $data), true)) {
                    return;
                }
            }
            // Bad luck, plugin could not restore the data, let's add normal membership.
            role_assign($data->roleid, $data->userid, $data->contextid);
            $message = "Restore of '$data->component/$data->itemid' role assignments is not supported, using manual role assignments instead.";
            $this->log($message, backup::LOG_WARNING);
        }
    }
770690
public function initIndexing(\PDO $db)
    {

        // delete everything before reset indexing
        $dir = opendir($this->SqliteDir);
        while ($file = readdir($dir)) {
            if ($file != '.' && $file != '..' && $file != 'indexing' && $file != 'dbfastcache') {
                unlink($this->SqliteDir . '/' . $file);
            }
        }

        $db->exec('DROP TABLE if exists "balancing"');
        $db->exec('CREATE TABLE "balancing" ("keyword" VARCHAR PRIMARY KEY NOT NULL UNIQUE, "db" INTEGER)');
        $db->exec('CREATE INDEX "db" ON "balancing" ("db")');
        $db->exec('CREATE UNIQUE INDEX "lookup" ON "balancing" ("keyword")');

    }
622110
protected function process_ltitoolsetting($data) {
        global $DB;

        $data = (object)$data;
        $data->toolproxyid = $this->get_new_parentid('ltitoolproxy');

        if (!$data->toolproxyid) {
            return;
        }

        $data->course = $this->get_courseid();
        $data->coursemoduleid = $this->task->get_moduleid();
        $DB->insert_record('lti_tool_settings', $data);
    }
552793
public function process_gradinform_rubric_filling($data) {
        global $DB;

        $data = (object)$data;
        $data->instanceid = $this->get_new_parentid('grading_instance');
        $data->criterionid = $this->get_mappingid('gradingform_rubric_criterion', $data->criterionid);
        $data->levelid = $this->get_mappingid('gradingform_rubric_level', $data->levelid);

        if (!empty($data->criterionid)) {
            $DB->insert_record('gradingform_rubric_fillings', $data);
        }

    }
801299
public function handle_message(\stdClass $messagedata) {
        $this->record = $this->get_data();
        return $this->handler->process_message($this->record, $messagedata);
    }
1285352
function process($data)
	{
		$using_xml = 0;
		$webspace = 1;

		if (isset($data["webspace"]))
		{
			if ($data["webspace"] == "false") // if explicitly set to false, don't use html output
				$webspace = 0;
		}

		if ( isset($data["debugging"]) || isset($data["debug"]) )
		{
			if ($data["debugging"] == "true" || $data["debug"] == "true"  )
			{
				$this->debugging = 1;

				# print out incoming hash
				if ($webspace)	// use html-friendly output
				{
					echo "at process, incoming data: <br>";

					while (list($key, $value) = each($data))
						 echo htmlspecialchars($key) . " = " . htmlspecialchars($value, ENT_COMPAT, CHARSET, TRUE) . "<BR>\n";
				}
				else      // don't use html output
				{
					echo "at process, incoming data: \n";

					while (list($key, $value) = each($data))
						echo "$key = $value\n";
				}

				reset($data);
			}
		}

		if (isset($data["xml"])) // if XML string is passed in, we'll use it
		{
			$using_xml = 1;
			$xml = $data["xml"];
		}
		else
		{
			//  otherwise convert incoming hash to XML string
			$xml = $this->buildXML($data);
		}

		// then set up transaction variables
		$key	= $data["keyfile"];
		$host	= $data["host"];
    $port	= $data["port"];


		# FOR PERFORMANCE, Use the 'extensions' statement in your php.ini to load
		# this library at PHP startup, then comment out the next seven lines

		// load library
		if (!extension_loaded('liblphp'))
		{
			if (!dl('liblphp.so'))
			{
				exit("cannot load liblphp.so, bye\n");
			}
		}

		if ($this->debugging)
		{
			if ($webspace)
				echo "<br>sending xml string:<br>" . htmlspecialchars($xml, ENT_COMPAT, CHARSET, TRUE) . "<br><br>";
			else
				echo "\nsending xml string:\n$xml\n\n";
		}

		// send transaction to LSGS
		$retstg = send_stg($xml, $key, $host, $port);


		if (strlen($retstg) < 4)
			exit ("cannot connect to lsgs, exiting");

		if ($this->debugging)
		{
			if ($this->webspace)	// we're web space
				echo "<br>server responds:<br>" . htmlspecialchars($retstg, ENT_COMPAT, CHARSET, TRUE) . "<br><br>";
			else						// not html output
				echo "\nserver responds:\n $retstg\n\n";
		}

		if ($using_xml != 1)
		{
			// convert xml response back to hash
			$retarr = $this->decodeXML($retstg);

			// and send it back to caller
			return ($retarr);
		}
		else
		{
			// send server response back
			return $retstg;
		}
	}
823571
protected function process_book_chapter($data) {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id;
        $data->course = $this->get_courseid();

        $data->bookid = $this->get_new_parentid('book');

        $newitemid = $DB->insert_record('book_chapters', $data);
        $this->set_mapping('book_chapter', $oldid, $newitemid, true);
    }
133641
public function where($data, $condition = NULL, $dbConnection = NULL)
    {
        $databaseQuery = new DatabaseQuery();
        $connection = $databaseQuery->checkConnection($dbConnection);

        $sqlQuery = self::whereClause($data, $condition, $connection);
        $query = $connection->prepare($sqlQuery);
        $query->execute();
        if ($query->rowCount()) {
            return new GetData($query->fetchAll($connection::FETCH_ASSOC));
        }
        throw new DataNotFoundException();
    }
274969
public function handleDropDatabase(): void
	{
		$this->checkHandlerPermission(false);

		$this->app->dropDatabase();
		$this->app->clearCache();
		$this->flashNotifier->success('dockbar.management.database.databaseDroped');
		$this->presenter->redirect('this');
	}