Will make the Global Manager include the Management Role of the extension
to install (if it exists).

@access public
@author Jerome Bogaerts <jerome@taotesting.com>
@return void
@since 2.4
432872
public function installManagementRole()
    {
        
        // Try to get a Management Role described by the extension itself.
        // (this information comes actually from the Manifest of the extension)
        $roleUri = $this->extension->getManifest()->getManagementRoleUri();
        if (! empty($roleUri)) {
            
            $role = new core_kernel_classes_Resource($roleUri);
            $roleService = tao_models_classes_RoleService::singleton();
            if (! $role->exists()) {
                // Management role does not exist yet, so we create it
                $roleClass = new core_kernel_classes_Class(TaoOntology::CLASS_URI_MANAGEMENT_ROLE);
                $roleLabel = $this->extension->getId() . ' Manager';
                $role = $roleClass->createInstance($roleLabel, $roleLabel . ' Role', $role->getUri());
                $roleService->includeRole($role, new core_kernel_classes_Resource(TaoRoles::BACK_OFFICE));
            }
            
            // Take the Global Manager role and make it include
            // the Management role of the currently installed extension.
            if ($role->getUri() !== TaoRoles::GLOBAL_MANAGER) {
                $globalManagerRole = new core_kernel_classes_Resource(TaoRoles::GLOBAL_MANAGER);
                $roleService->includeRole($globalManagerRole, $role);
            }
            
            common_Logger::d("Management Role " . $role->getUri() . " created for extension '" . $this->extension->getId() . "'.");
        } else {
            // There is no Management role described by the Extension Manifest.
            common_Logger::i("No management role for extension '" . $this->extension->getId() . "'.");
        }
    }
463888
private function processAdministrator()
	{
		$sourceFolder = $this->getSourceFolder();
		$this->processComponents($sourceFolder . '/administrator/components', $this->target . '/administrator');
		$this->processLanguage($sourceFolder . '/administrator/language', $this->target . '/administrator');
		$this->processModules($sourceFolder . '/administrator/modules', $this->target . '/administrator/modules');
	}
953958
public function on_root_element_end() {
        global $CFG;

        // restore the stashes prepared by other handlers for us
        $backupinfo         = $this->converter->get_stash('backup_info');
        $originalcourseinfo = $this->converter->get_stash('original_course_info');

        ////////////////////////////////////////////////////////////////////////
        // write moodle_backup.xml
        ////////////////////////////////////////////////////////////////////////
        $this->open_xml_writer('moodle_backup.xml');

        $this->xmlwriter->begin_tag('moodle_backup');
        $this->xmlwriter->begin_tag('information');

        // moodle_backup/information
        $this->xmlwriter->full_tag('name', $backupinfo['name']);
        $this->xmlwriter->full_tag('moodle_version', $backupinfo['moodle_version']);
        $this->xmlwriter->full_tag('moodle_release', $backupinfo['moodle_release']);
        $this->xmlwriter->full_tag('backup_version', $CFG->backup_version); // {@see restore_prechecks_helper::execute_prechecks}
        $this->xmlwriter->full_tag('backup_release', $CFG->backup_release);
        $this->xmlwriter->full_tag('backup_date', $backupinfo['date']);
        // see the commit c0543b - all backups created in 1.9 and later declare the
        // information or it is considered as false
        if (isset($backupinfo['mnet_remoteusers'])) {
            $this->xmlwriter->full_tag('mnet_remoteusers', $backupinfo['mnet_remoteusers']);
        } else {
            $this->xmlwriter->full_tag('mnet_remoteusers', false);
        }
        $this->xmlwriter->full_tag('original_wwwroot', $backupinfo['original_wwwroot']);
        // {@see backup_general_helper::backup_is_samesite()}
        if (isset($backupinfo['original_site_identifier_hash'])) {
            $this->xmlwriter->full_tag('original_site_identifier_hash', $backupinfo['original_site_identifier_hash']);
        } else {
            $this->xmlwriter->full_tag('original_site_identifier_hash', null);
        }
        $this->xmlwriter->full_tag('original_course_id', $originalcourseinfo['original_course_id']);
        $this->xmlwriter->full_tag('original_course_fullname', $originalcourseinfo['original_course_fullname']);
        $this->xmlwriter->full_tag('original_course_shortname', $originalcourseinfo['original_course_shortname']);
        $this->xmlwriter->full_tag('original_course_startdate', $originalcourseinfo['original_course_startdate']);
        $this->xmlwriter->full_tag('original_system_contextid', $this->converter->get_contextid(CONTEXT_SYSTEM));
        // note that even though we have original_course_contextid available, we regenerate the
        // original course contextid using our helper method to be sure that the data are consistent
        // within the MBZ file
        $this->xmlwriter->full_tag('original_course_contextid', $this->converter->get_contextid(CONTEXT_COURSE));

        // moodle_backup/information/details
        $this->xmlwriter->begin_tag('details');
        $this->write_xml('detail', array(
            'backup_id'     => $this->converter->get_id(),
            'type'          => backup::TYPE_1COURSE,
            'format'        => backup::FORMAT_MOODLE,
            'interactive'   => backup::INTERACTIVE_YES,
            'mode'          => backup::MODE_CONVERTED,
            'execution'     => backup::EXECUTION_INMEDIATE,
            'executiontime' => 0,
        ), array('/detail/backup_id'));
        $this->xmlwriter->end_tag('details');

        // moodle_backup/information/contents
        $this->xmlwriter->begin_tag('contents');

        // moodle_backup/information/contents/activities
        $this->xmlwriter->begin_tag('activities');
        $activitysettings = array();
        foreach ($this->converter->get_stash('coursecontents') as $activity) {
            $modinfo = $this->converter->get_stash('modinfo_'.$activity['modulename']);
            $modinstance = $modinfo['instances'][$activity['instanceid']];
            $this->write_xml('activity', array(
                'moduleid'      => $activity['cmid'],
                'sectionid'     => $activity['sectionid'],
                'modulename'    => $activity['modulename'],
                'title'         => $modinstance['name'],
                'directory'     => 'activities/'.$activity['modulename'].'_'.$activity['cmid']
            ));
            $activitysettings[] = array(
                'level'     => 'activity',
                'activity'  => $activity['modulename'].'_'.$activity['cmid'],
                'name'      => $activity['modulename'].'_'.$activity['cmid'].'_included',
                'value'     => (($modinfo['included'] === 'true' and $modinstance['included'] === 'true') ? 1 : 0));
            $activitysettings[] = array(
                'level'     => 'activity',
                'activity'  => $activity['modulename'].'_'.$activity['cmid'],
                'name'      => $activity['modulename'].'_'.$activity['cmid'].'_userinfo',
                //'value'     => (($modinfo['userinfo'] === 'true' and $modinstance['userinfo'] === 'true') ? 1 : 0));
                'value'     => 0); // todo hardcoded non-userinfo for now
        }
        $this->xmlwriter->end_tag('activities');

        // moodle_backup/information/contents/sections
        $this->xmlwriter->begin_tag('sections');
        $sectionsettings = array();
        foreach ($this->converter->get_stash_itemids('sectioninfo') as $sectionid) {
            $sectioninfo = $this->converter->get_stash('sectioninfo', $sectionid);
            $sectionsettings[] = array(
                'level'     => 'section',
                'section'   => 'section_'.$sectionid,
                'name'      => 'section_'.$sectionid.'_included',
                'value'     => 1);
            $sectionsettings[] = array(
                'level'     => 'section',
                'section'   => 'section_'.$sectionid,
                'name'      => 'section_'.$sectionid.'_userinfo',
                'value'     => 0); // @todo how to detect this from moodle.xml?
            $this->write_xml('section', array(
                'sectionid' => $sectionid,
                'title'     => $sectioninfo['number'], // because the title is not available
                'directory' => 'sections/section_'.$sectionid));
        }
        $this->xmlwriter->end_tag('sections');

        // moodle_backup/information/contents/course
        $this->write_xml('course', array(
            'courseid'  => $originalcourseinfo['original_course_id'],
            'title'     => $originalcourseinfo['original_course_shortname'],
            'directory' => 'course'));
        unset($originalcourseinfo);

        $this->xmlwriter->end_tag('contents');

        // moodle_backup/information/settings
        $this->xmlwriter->begin_tag('settings');

        // fake backup root seetings
        $rootsettings = array(
            'filename'         => $backupinfo['name'],
            'users'            => 0, // @todo how to detect this from moodle.xml?
            'anonymize'        => 0,
            'role_assignments' => 0,
            'activities'       => 1,
            'blocks'           => 1,
            'filters'          => 0,
            'comments'         => 0,
            'userscompletion'  => 0,
            'logs'             => 0,
            'grade_histories'  => 0,
        );
        unset($backupinfo);
        foreach ($rootsettings as $name => $value) {
            $this->write_xml('setting', array(
                'level' => 'root',
                'name'  => $name,
                'value' => $value));
        }
        unset($rootsettings);

        // activity settings populated above
        foreach ($activitysettings as $activitysetting) {
            $this->write_xml('setting', $activitysetting);
        }
        unset($activitysettings);

        // section settings populated above
        foreach ($sectionsettings as $sectionsetting) {
            $this->write_xml('setting', $sectionsetting);
        }
        unset($sectionsettings);

        $this->xmlwriter->end_tag('settings');

        $this->xmlwriter->end_tag('information');
        $this->xmlwriter->end_tag('moodle_backup');

        $this->close_xml_writer();

        ////////////////////////////////////////////////////////////////////////
        // write files.xml
        ////////////////////////////////////////////////////////////////////////
        $this->open_xml_writer('files.xml');
        $this->xmlwriter->begin_tag('files');
        foreach ($this->converter->get_stash_itemids('files') as $fileid) {
            $this->write_xml('file', $this->converter->get_stash('files', $fileid), array('/file/id'));
        }
        $this->xmlwriter->end_tag('files');
        $this->close_xml_writer('files.xml');

        ////////////////////////////////////////////////////////////////////////
        // write scales.xml
        ////////////////////////////////////////////////////////////////////////
        $this->open_xml_writer('scales.xml');
        $this->xmlwriter->begin_tag('scales_definition');
        foreach ($this->converter->get_stash_itemids('scales') as $scaleid) {
            $this->write_xml('scale', $this->converter->get_stash('scales', $scaleid), array('/scale/id'));
        }
        $this->xmlwriter->end_tag('scales_definition');
        $this->close_xml_writer('scales.xml');

        ////////////////////////////////////////////////////////////////////////
        // write course/inforef.xml
        ////////////////////////////////////////////////////////////////////////
        $this->open_xml_writer('course/inforef.xml');
        $this->xmlwriter->begin_tag('inforef');

        $this->xmlwriter->begin_tag('fileref');
        // legacy course files
        $fileids = $this->converter->get_stash('course_files_ids');
        if (is_array($fileids)) {
            foreach ($fileids as $fileid) {
                $this->write_xml('file', array('id' => $fileid));
            }
        }
        // todo site files
        // course summary files
        $fileids = $this->converter->get_stash('course_summary_files_ids');
        if (is_array($fileids)) {
            foreach ($fileids as $fileid) {
                $this->write_xml('file', array('id' => $fileid));
            }
        }
        $this->xmlwriter->end_tag('fileref');

        $this->xmlwriter->begin_tag('question_categoryref');
        foreach ($this->converter->get_stash_itemids('question_categories') as $questioncategoryid) {
            $this->write_xml('question_category', array('id' => $questioncategoryid));
        }
        $this->xmlwriter->end_tag('question_categoryref');

        $this->xmlwriter->end_tag('inforef');
        $this->close_xml_writer();

        // make sure that the files required by the restore process have been generated.
        // missing file may happen if the watched tag is not present in moodle.xml (for example
        // QUESTION_CATEGORIES is optional in moodle.xml but questions.xml must exist in
        // moodle2 format) or the handler has not been implemented yet.
        // apparently this must be called after the handler had a chance to create the file.
        $this->make_sure_xml_exists('questions.xml', 'question_categories');
        $this->make_sure_xml_exists('groups.xml', 'groups');
        $this->make_sure_xml_exists('outcomes.xml', 'outcomes_definition');
        $this->make_sure_xml_exists('users.xml', 'users');
        $this->make_sure_xml_exists('course/roles.xml', 'roles',
            array('role_assignments' => array(), 'role_overrides' => array()));
        $this->make_sure_xml_exists('course/enrolments.xml', 'enrolments',
            array('enrols' => array()));
    }
846993
def add_manager(model):
    
    if model._meta.abstract:
        return
    # Make all managers local for this model to fix patching parent model managers
    model._meta.local_managers = model._meta.managers

    for current_manager in model._meta.local_managers:
        prev_class = current_manager.__class__
        patch_manager_class(current_manager)
        if model._default_manager.__class__ is prev_class:
            # Normally model._default_manager is a reference to one of model's managers
            # (and would be patched by the way).
            # However, in some rare situations (mostly proxy models)
            # model._default_manager is not the same instance as one of managers, but it
            # share the same class.
            model._default_manager.__class__ = current_manager.__class__
    patch_manager_class(model._base_manager)
    model._meta.base_manager_name = 'objects'
    model._meta._expire_cache()
753949
public function enable()
    {
        $this->manager->enable($this);

        if ($this->referenced) {
            $this->manager->reference($this);
        }
    }
931812
protected function createSuperadmin()
    {
        $this->setCliMessage('Creating superadmin...');

        $user = array(
            'status' => 1,
            'name' => 'Superadmin',
            'store_id' => $this->context['store_id'],
            'email' => $this->data['user']['email'],
            'password' => $this->data['user']['password']
        );

        $user_id = $this->getUserModel()->add($user);

        $this->config->set('user_superadmin', $user_id);
        $this->setContext('user_id', $user_id);
    }
663758
public function add()
    {
        $this->loadModel('Content.ContentTypes');
        $this->loadModel('User.Roles');
        $type = $this->ContentTypes->newEntity();

        if ($this->request->data()) {
            $type = $this->ContentTypes->patchEntity($type, $this->request->data());
            $errors = $type->errors();
            $success = empty($errors);

            if ($success) {
                $success = $this->ContentTypes->save($type);
                if ($success) {
                    $this->Flash->success(__d('content', 'Content type created, now attach some fields.'));
                    $this->redirect(['plugin' => 'Content', 'controller' => 'fields', 'type' => $type->slug]);
                }
            }

            if (!$success) {
                $this->Flash->danger(__d('content', 'Content type could not be created, check your information.'));
            }
        }

        $roles = $this->Roles->find('list');
        $this->title(__d('content', 'Define New Content Type'));
        $this->set(compact('type', 'roles'));
        $this->set('languages', LocaleToolbox::languagesList());
        $this->Breadcrumb
            ->push('/admin/content/manage')
            ->push(__d('content', 'Content Types'), '/admin/content/types')
            ->push(__d('content', 'Creating Content Type'), '#');
    }
692262
public function autoload_on_admin()
	{
		$this->on_admin();
		// Addons
		for ( $i = count( $this->addons ) - 1; $i >= 0; --$i ) {
			$this->addons[$i]->on_admin();
		}
	}
206688
protected function wizardAddUser()
    {
        // Required
        $this->validatePrompt('email', $this->text('E-mail'), 'user');
        $this->validatePrompt('password', $this->text('Password'), 'user');
        $this->validatePrompt('name', $this->text('Name'), 'user');

        // Optional
        $this->validatePrompt('role_id', $this->text('Role ID'), 'user', 0);
        $this->validatePrompt('store_id', $this->text('Store ID'), 'user', $this->config->get('store', 1));
        $this->validatePrompt('timezone', $this->text('Timezone'), 'user', $this->config->get('timezone', 'Europe/London'));
        $this->validatePrompt('status', $this->text('Status'), 'user', 0);
        $this->validatePrompt('data', $this->text('Data'), 'user');
        $this->setSubmittedJson('data');

        $this->validateComponent('user');
        $this->addUser();
    }
636462
protected function registerInstallCommand(): void
    {
        $this->app->singleton('orchestra.commands.tenanti.install', function (Application $app) {
            return new InstallCommand($app->make('orchestra.tenanti'));
        });
    }
493100
public function wizardInstallDrupal() {
    if (!$this->getInspector()->isMySqlAvailable()) {
      return FALSE;
    }
    if (!$this->getInspector()->isDrupalInstalled()) {
      $this->logger->warning('Drupal is not installed.');
      $confirm = $this->confirm("Do you want to install Drupal?");
      if ($confirm) {
        $bin = $this->getConfigValue('composer.bin');
        $this->executor
          ->execute("$bin/blt setup")
          ->interactive($this->input()->isInteractive())
          ->run();
        $this->getInspector()->clearState();
      }
    }
  }
1343204
protected function addRole()
    {
        if (!$this->isError()) {
            $id = $this->role->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
746567
protected function wizardAddRole()
    {
        $this->validatePrompt('name', $this->text('Name'), 'user_role');
        $this->validatePromptList('permissions', $this->text('Permissions'), 'user_role');
        $this->validatePrompt('redirect', $this->text('Redirect'), 'user_role', '');
        $this->validatePrompt('status', $this->text('Status'), 'user_role', 0);
        $this->setSubmittedList('permissions');

        $this->validateComponent('user_role');
        $this->addRole();
    }
1281721
public function editInstall()
    {
        $this->controlAccessInstall();
        $this->translation->set($this->install_language, null);
        $this->setTitleEditInstall();

        $requirements = $this->getRequirementsInstall();
        $issues = $this->getRequirementErrorsInstall($requirements);

        $this->setData('issues', $issues);
        $this->setData('requirements', $requirements);
        $this->setData('settings.installer', 'default');
        $this->setData('timezones', gplcart_timezones());
        $this->setData('language', $this->install_language);
        $this->setData('handlers', $this->install->getHandlers());
        $this->setData('languages', $this->getLanguagesInstall());
        $this->setData('severity', $this->getSeverityInstall($issues));
        $this->setData('settings.store.language', $this->install_language);

        $this->submitEditInstall();
        $this->outputEditInstall();
    }
826148
public function setup()
	{
		$this->addRule('title', function($data)
		{
			if (!isset($data['title']) || $data['title'] == '')
			{
				return 'Title is required.';
			}

			$exist = self::all()
				->whereEquals('title', $data['title'])
				->whereEquals('parent_id', $data['parent_id'])
				->where('id', '<>', $data['id'])
				->count();

			return $exist ? 'Access group title already exists.' : false;
		});
	}
1310570
public function onKernelTerminate()
    {
        foreach ($this->managers as $key => $value) {
            if ($value['force_commit']) {
                try {
                    /** @var Manager $manager */
                    $manager = $this->container->get(sprintf('es.manager.%s', $key));
                } catch (\Exception $e) {
                    continue;
                }
                $manager->commit();
            }
        }
    }
694901
private function setup_globals() {
		$this->file       = __FILE__;
		$this->basename   = plugin_basename( $this->file );
		$this->plugin_dir = plugin_dir_path( $this->file ) . 'wp-multi-network/';
		$this->plugin_url = plugin_dir_url( $this->file ) . 'wp-multi-network/';
	}