Builds a configured data backend.

If configured this method would automatically install the backend. I.e. a first
call will take some amount of time.

@return DataBackend
@throws DataBackendException
777079
private function buildDataBackend()
    {
        $configuration = ConfigurationRegistry::getConfiguration();
        $backend = $this->makeDataBackend();

        // Installation
        if ($configuration->isAutomaticInstallation() && ! $backend->isInstalled()) {
            $lock = new Lock(self::INSTALL_LOCK);
            $lock->executeOnce(
                function () use ($backend) {
                    $backend->install();
                }
            );
        }

        // Update hook
        register_shutdown_function(array($this, "applyUpdatePlan"), $backend);

        return $backend;
    }
121899
public function build(): ResolveNodeRequest
	{
		$instance = new ResolveNodeRequest();
		$instance->nodeId = $this->nodeId;
		$instance->backendNodeId = $this->backendNodeId;
		$instance->objectGroup = $this->objectGroup;
		$instance->executionContextId = $this->executionContextId;
		return $instance;
	}
156174
private function build() {
        $this->getAbstractClass()->setDocumentation($this->getComment());
        $this->getAbstractClass()->setName(ucfirst($this->getTableName()));
        $this->getAbstractClass()->addUse(
            $this->getConfiguration()->getRootNamespace()
            . '\Models\\' . $this->getConfiguration()->getModelSubNamespace()
            . '\Base'
        );
        $this->getAbstractClass()->addUse('Bullhorn\FastRest\Api\Models\GeneratedInterface');
        $this->getAbstractClass()->setImplements(['GeneratedInterface']);
        $this->getAbstractClass()->setNamespace(
            $this->getConfiguration()->getRootNamespace()
            . '\Models\\' . $this->getConfiguration()->getModelSubNamespace()
            . '\Generated'
        );
        $this->getAbstractClass()->addUse(
            $this->getConfiguration()->getRootNamespace()
            . '\Models\\' . $this->getConfiguration()->getModelSubNamespace()
            . '\\' . ucfirst($this->getTableName()) . ' as ChildModel'
        );
        $this->getAbstractClass()->setExtends('Base');
        $this->getAbstractClass()->setAbstract(true);
        $this->buildIdField();

        $this->buildEnumConstants();

        $this->buildInitialize();
        $this->buildFieldsTypes();
        $this->buildVariableDefinitions();
        $this->buildOnConstruct();

        $this->buildGetSource();
        $this->buildAddJoin();

        $this->buildFindFirst();
        $this->buildFind();

        $this->buildGettersAndSetters();
        $this->buildRelationshipGetters();
        $this->buildColumnMap();
        $this->buildRelationshipsList();
    }
757433
protected function buildDatabase(): DatabaseAdapter {
		$database = new SqliteDatabase($this->determineDbCharset(), 
				$this->getPersistedMetaEntities(), $this->determineDbAttrs());
		
		foreach ($database->getMetaEntities() as $metaEntity) {
			if (!$metaEntity instanceof Table) continue;
			
			$this->metaEntityBuilder->applyIndexesForTable(
					SqliteDatabase::FIXED_DATABASE_NAME, $metaEntity);
		}
		
		return $database;
	}
81431
protected function buildModel()
    {
        $config = $this->getGeneratorConfig();
        $con = $this->getConnection();

        $this->log('Reading database structure...');

        $database = new Database($this->getDatabaseName());
        $database->setPlatform($config->getConfiguredPlatform($con));
        $database->setDefaultIdMethod(IDMethod::NATIVE);
        $parser = $config->getConfiguredSchemaParser($con);
        $nbTables = $parser->parse($database, $this);

        $this->log(sprintf('Successfully reverse engineered %d tables', $nbTables));

        return $database;
    }
85253
public function getDataSource()
    {
        if (empty($this->dataSource)) {
            // Assign the default data source, now that one is needed.
            $this->dataSource = $this->getDefaultDataSource();
            // If, after assigning the data source, there is still nothing in
            // the property, then fail.
            if (empty($this->dataSource)) {
                throw new Exception('No datasource has been defined.');
            }
        }

        return $this->dataSource;
    }
389826
public function create() {
    $data = Ensure::Input(func_get_args());
    $data = $data->get();

    if (isset($data['domainId'])) {
      new PathResource($this, array(
         "domains" => $data['domainId'],
         "endpoints" => ""
          )
      );
    }

    return parent::create($data);
  }
207722
public function build()
    {
        $options           = $this->suppliedOptions;
        $this->tablePrefix = $this->db->getTablePrefix();
        $nested            = $this->getNestedRelationships($options['relationship']);

        $relevantName      = $nested['pieces'][sizeof($nested['pieces']) - 1];
        $relevantModel     = $nested['models'][sizeof($nested['models']) - 2];
        $options['nested'] = $nested;

        $relationship = $relevantModel->{$relevantName}();
        $selectTable  = $options['column_name'].'_'.$this->tablePrefix.$relationship->getRelated()->getTable();

        //set the relationship object so we can use it later
        $this->relationshipObject = $relationship;

        //replace the (:table) with the generated $selectTable
        $options['select'] = str_replace('(:table)', $selectTable, $options['select']);

        $this->suppliedOptions = $options;
    }
632930
public DatasourceDependency build() {
        return new DatasourceDependency(name, description, type, subtype, datasources, criticality, expectations);
    }
214982
public function build(): PushNodesByBackendIdsToFrontendRequest
	{
		$instance = new PushNodesByBackendIdsToFrontendRequest();
		if ($this->backendNodeIds === null) {
			throw new BuilderException('Property [backendNodeIds] is required.');
		}
		$instance->backendNodeIds = $this->backendNodeIds;
		return $instance;
	}
264926
public function initializeObject()
    {
        if (!$this->backend instanceof Backend\BackendInterface) {
            throw new MissingBackendException('A persistence backend must be set prior to initializing the persistence manager.', 1215508456);
        }
        $this->backend->setPersistenceManager($this);
        $this->backend->initialize($this->settings['backendOptions']);
    }
690536
public function build() {

        // If we have decided not to backup activities, prevent anything to be built
        if (!$this->get_setting_value('activities')) {
            $this->built = true;
            return;
        }

        // Add some extra settings that related processors are going to need
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_MODID, base_setting::IS_INTEGER, $this->moduleid));
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $this->get_courseid()));
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_SECTIONID, base_setting::IS_INTEGER, $this->sectionid));
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_MODNAME, base_setting::IS_FILENAME, $this->modulename));
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_ACTIVITYID, base_setting::IS_INTEGER, $this->activityid));
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $this->contextid));

        // Create the activity directory
        $this->add_step(new create_taskbasepath_directory('create_activity_directory'));

        // Generate the module.xml file, containing general information for the
        // activity and from its related course_modules record and availability
        $this->add_step(new backup_module_structure_step('module_info', 'module.xml'));

        // Annotate the groups used in already annotated groupings if groups are to be backed up.
        if ($this->get_setting_value('groups')) {
            $this->add_step(new backup_annotate_groups_from_groupings('annotate_groups'));
        }

        // Here we add all the common steps for any activity and, in the point of interest
        // we call to define_my_steps() is order to get the particular ones inserted in place.
        $this->define_my_steps();

        // Generate the roles file (optionally role assignments and always role overrides)
        $this->add_step(new backup_roles_structure_step('activity_roles', 'roles.xml'));

        // Generate the filter file (conditionally)
        if ($this->get_setting_value('filters')) {
            $this->add_step(new backup_filters_structure_step('activity_filters', 'filters.xml'));
        }

        // Generate the comments file (conditionally)
        if ($this->get_setting_value('comments')) {
            $this->add_step(new backup_comments_structure_step('activity_comments', 'comments.xml'));
        }

        // Generate the userscompletion file (conditionally)
        if ($this->get_setting_value('userscompletion')) {
            $this->add_step(new backup_userscompletion_structure_step('activity_userscompletion', 'completion.xml'));
        }

        // Generate the logs file (conditionally)
        if ($this->get_setting_value('logs')) {
            // Legacy logs.
            $this->add_step(new backup_activity_logs_structure_step('activity_logs', 'logs.xml'));
            // New log stores.
            $this->add_step(new backup_activity_logstores_structure_step('activity_logstores', 'logstores.xml'));
        }

        // Generate the calendar events file (conditionally)
        if ($this->get_setting_value('calendarevents')) {
            $this->add_step(new backup_calendarevents_structure_step('activity_calendar', 'calendar.xml'));
        }

        // Fetch all the activity grade items and put them to backup_ids
        $this->add_step(new backup_activity_grade_items_to_ids('fetch_activity_grade_items'));

        // Generate the grades file
        $this->add_step(new backup_activity_grades_structure_step('activity_grades', 'grades.xml'));

        // Generate the grading file (conditionally)
        $this->add_step(new backup_activity_grading_structure_step('activity_grading', 'grading.xml'));

        // Generate the grade history file. The setting 'grade_histories' is handled in the step.
        $this->add_step(new backup_activity_grade_history_structure_step('activity_grade_history', 'grade_history.xml'));

        // Generate the competency file.
        $this->add_step(new backup_activity_competencies_structure_step('activity_competencies', 'competencies.xml'));

        // Annotate the scales used in already annotated outcomes
        $this->add_step(new backup_annotate_scales_from_outcomes('annotate_scales'));

        // NOTE: Historical grade information is saved completely at course level only (see 1.9)
        // not per activity nor per selected activities (all or nothing).

        // Generate the inforef file (must be after ALL steps gathering annotations of ANY type)
        $this->add_step(new backup_inforef_structure_step('activity_inforef', 'inforef.xml'));

        // Migrate the already exported inforef entries to final ones
        $this->add_step(new move_inforef_annotations_to_final('migrate_inforef'));

        // At the end, mark it as built
        $this->built = true;
    }
1164412
public function buildSql()
    {
        $sqlDbMapContent = "# Sqlfile -> Database map\n";
        foreach ($this->getDatabases() as $datasource => $database) {
            $platform = $database->getPlatform();
            $filename = $database->getName() . '.sql';

            if ($this->getGeneratorConfig()->getBuildProperty('disableIdentifierQuoting')) {
                $platform->setIdentifierQuoting(false);
            }

            $ddl = $platform->getAddTablesDDL($database);

            $file = $this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $filename;
            if (file_exists($file) && $ddl == file_get_contents($file)) {
                // Unchanged
            } else {
                file_put_contents($file, $ddl);
            }

            $sqlDbMapContent .= sprintf("%s=%s\n", $filename, $datasource);
        }

        file_put_contents($this->getSqlDbMapFilename(), $sqlDbMapContent);
    }
258766
public function buildData()
    {
        $options = $this->getOptions();
        
        $total = $this->getCount();
        
        $data  = $this->getResult();
        
        $dataEvent = new DataEvent($this->dataGrid->getName(), $data);
        
        $this->dispatcher
            ->dispatch(DataGridEvents::onDataReady, $dataEvent);
        
        $this->data = $dataEvent->getData();
        
        $rows = array();
        
        if ($options['page'] && $options['records']){
            $total = ceil($this->getCount() / $options['records']);
        }

        foreach ($this->getData() as $row) {
            $colData = array();
            foreach($this->getDataGrid()->getColModel() as $col){
                $colData[] = $row[$col['name']];
            }

            $rows[] = array('id' => $row['id'], 'cell' => $colData);
        }
        
        $processedData =  array(
            'page'    => $options['page'],
            'total'   => (int) $total,
            'records' => $this->getCount(),
            'rows'    => $rows
        );
        
        $this->processedData = $processedData;
        
        return $this;
    }
736454
public function build() {

        // Set the backup::VAR_CONTEXTID setting to course context as far as next steps require that
        $coursectxid = context_course::instance($this->get_courseid())->id;
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $coursectxid));

        // Add some extra settings that related processors are going to need
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_SECTIONID, base_setting::IS_INTEGER, $this->sectionid));
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $this->get_courseid()));

        // Create the section directory
        $this->add_step(new create_taskbasepath_directory('create_section_directory'));

        // Create the section.xml common file (course_sections)
        $this->add_step(new backup_section_structure_step('section_commons', 'section.xml'));

        // Generate the inforef file (must be after ALL steps gathering annotations of ANY type)
        $this->add_step(new backup_inforef_structure_step('section_inforef', 'inforef.xml'));

        // Migrate the already exported inforef entries to final ones
        $this->add_step(new move_inforef_annotations_to_final('migrate_inforef'));

        // At the end, mark it as built
        $this->built = true;
    }
1019831
public function build()
    {
        $job = new JobDetail();

//        $job->setJobClass($this->jobClass);

        if(null == $this->key) {
            $this->key = new Key(Key::createUniqueName(null), null);
        }

        $job->setKey($this->key);
        $job->setDescription($this->description);
        $job->setDurable($this->durability);
//        $job->setRequestsRecovery($this->shouldRecover);
        $job->setJobClass($this->jobClass);
        $job->setJobDataMap($this->jobDataMap);

        return $job;
    }
274753
protected function buildData()
  {
    $handle = opendir($this->folderPath);
    while (false !== ($file = readdir($handle))) {
      $vext = str_replace(',', '|', strtolower($this->extensions));
      if (!is_dir($file) && $file != '.' && $file != '..' && ($this->extensions == '' || preg_match("/\.(" . $vext . ")$/", strtolower($file)))) {
        $this->files[] = $file;
      }
    }
  }