MediaWiki master
TaskFactory.php
Go to the documentation of this file.
1<?php
2
4
5use Wikimedia\ObjectFactory\ObjectFactory;
6
13 public const PROFILE_INSTALLER = 'installer';
14 public const PROFILE_ADD_WIKI = 'installPreConfigured';
15 public const PROFILE_WEB_UPGRADE = 'web-upgrade';
16
21 private const CORE_SPECS = [
22 [ 'class' => ExtensionsProvider::class, 'profile' => self::PROFILE_INSTALLER ],
23 [ 'class' => CreateDatabaseTask::class, 'db' => 'mysql' ],
24 [ 'class' => MysqlCreateUserTask::class, 'db' => 'mysql' ],
25 [ 'class' => CreateDatabaseTask::class, 'db' => 'postgres' ],
26 [ 'class' => PostgresCreateUserTask::class, 'db' => 'postgres' ],
27 [ 'class' => PostgresPlTask::class, 'db' => 'postgres' ],
28 [ 'class' => PostgresCreateSchemaTask::class, 'db' => 'postgres' ],
29 [ 'class' => SqliteCreateDatabaseTask::class, 'db' => 'sqlite' ],
30 [ 'class' => SqliteCreateSearchIndexTask::class, 'db' => 'sqlite' ],
31 [ 'class' => CreateTablesTask::class ],
32 [ 'class' => PopulateSiteStatsTask::class ],
33 [ 'class' => PopulateInterwikiTask::class ],
34 [ 'class' => InsertUpdateKeysTask::class ],
35 [ 'class' => RestoredServicesProvider::class, 'profile' => self::PROFILE_INSTALLER ],
36 [ 'class' => AddWikiRestoredServicesProvider::class, 'profile' => self::PROFILE_ADD_WIKI ],
37 [ 'class' => CreateExternalDomainsTask::class, 'profile' => self::PROFILE_ADD_WIKI ],
38 [ 'class' => ExtensionTablesTask::class ],
39 [ 'class' => InitialContentTask::class ],
40 [ 'class' => CreateSysopTask::class, 'profile' => self::PROFILE_INSTALLER ],
41 [ 'class' => MailingListSubscribeTask::class, 'profile' => self::PROFILE_INSTALLER ],
42 ];
43
44 private const WEB_UPGRADE_SPECS = [
45 [ 'class' => WebUpgradeExtensionsProvider::class ],
46 [ 'class' => RestoredServicesProvider::class ],
47 [ 'class' => WebUpgradeTask::class ],
48 ];
49
51 private $objectFactory;
53 private $context;
54
55 public function __construct( ObjectFactory $objectFactory, ITaskContext $context ) {
56 $this->objectFactory = $objectFactory;
57 $this->context = $context;
58 }
59
67 public function registerMainTasks( TaskList $list, string $profile ) {
68 $this->registerTasks( $list, $profile, self::CORE_SPECS );
69 }
70
78 public function registerExtensionTasks( TaskList $list, string $profile ) {
79 $specs = $this->context->getProvision( 'ExtensionTaskSpecs' );
80 if ( !is_array( $specs ) ) {
81 throw new \RuntimeException( 'Invalid value for ExtensionTaskSpecs' );
82 }
83 $this->registerTasks( $list, $profile, $specs );
84 }
85
86 public function registerWebUpgradeTasks( TaskList $list ) {
87 $this->registerTasks( $list, self::PROFILE_WEB_UPGRADE, self::WEB_UPGRADE_SPECS );
88 }
89
97 private function registerTasks( TaskList $list, string $profile, array $specs ) {
98 $dbType = $this->context->getDbType();
99 foreach ( $specs as $spec ) {
100 if ( isset( $spec['db'] ) && $spec['db'] !== $dbType ) {
101 continue;
102 }
103 if ( isset( $spec['profile'] ) && $spec['profile'] !== $profile ) {
104 continue;
105 }
106 $list->add( $this->create( $spec ) );
107 }
108 }
109
128 public function create( array $spec ): Task {
129 if ( isset( $spec['callback'] ) ) {
130 $task = new CallbackTask( $spec );
131 } else {
132 $allowedParamNames = [ 'factory', 'class', 'args' ];
133 $factorySpec = array_intersect_key( $spec, array_fill_keys( $allowedParamNames, true ) );
134 $task = $this->objectFactory->createObject( $factorySpec );
135 if ( !( $task instanceof Task ) ) {
136 throw new \RuntimeException( 'Invalid task type' );
137 }
138 }
139
140 $schemaBasePath = $spec['schemaBasePath'] ?? $this->getCoreSchemaBasePath();
141
142 $task->initBase(
143 $this->context,
144 $schemaBasePath,
145 );
146 return $task;
147 }
148
149 private function getCoreSchemaBasePath() {
150 return MW_INSTALL_PATH . '/sql';
151 }
152}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
An installer task which calls a callback function.
Factory for installer tasks.
registerExtensionTasks(TaskList $list, string $profile)
Populate the task list with extension installer tasks provided by the current task context.
registerMainTasks(TaskList $list, string $profile)
Populate the task list with core installer tasks which are shared by the various installation methods...
create(array $spec)
Create a task object.
__construct(ObjectFactory $objectFactory, ITaskContext $context)
A container for tasks, with sorting of tasks by their declared dependencies.
Definition TaskList.php:13
add(Task $task)
Add a task to the list.
Definition TaskList.php:23
Base class for installer tasks.
Definition Task.php:24
Dependency bundle and execution context for installer tasks.