/** * Sets up the required tables for a WordPress multisite installation if not present in the database. * * @param bool $subdomainInstall Whether this is a subdomain multisite installation or a subfolder one. * * @param bool $needHtaccess Whether an `.htaccess` file should be put in place or not. * @param int $sleep A number in seconds the method should wait for db and files operation to complete; def. `0`. * * @return array An array containing exit information about multisite tables created/altered/updated. * @throws ModuleConfigException */ public function haveMultisiteInDatabase($subdomainInstall = true, $needHtaccess = false, $sleep = 0) { $this->isSubdomainMultisiteInstall = $subdomainInstall; $this->needHtaccess = $needHtaccess; $this->isMultisite = true; $dbh = $this->driver->getDbh(); foreach ($this->tables->multisiteTables() as $table) { $operation = 'create'; $prefixedTableName = $this->grabPrefixedTableNameFor($table); if ($this->_seeTableInDatabase($prefixedTableName)) { $query = $this->tables->getAlterTableQuery($table, $this->config['tablePrefix']); $operation = 'alter'; } else { $query = $this->tables->getCreateTableQuery($table, $this->config['tablePrefix']); } if (!empty($query)) { $sth = $dbh->prepare($query); $this->debugSection('Query', $sth->queryString); $out[$table] = ['operation' => $operation, 'exit' => $sth->execute([])]; } else { $out[$table] = ['operation' => $operation, 'exit' => false]; } } $domain = $this->getSiteDomain(); if (!$this->countInDatabase($this->grabSiteTableName(), ['domain' => $domain])) { $this->haveInDatabase($this->grabSiteTableName(), ['domain' => $domain, 'path' => '/']); } if (!$this->countInDatabase($this->grabBlogsTableName(), ['blog_id' => 1])) { $this->query("ALTER TABLE {$this->grabBlogsTableName()} AUTO_INCREMENT=1"); $mainBlogData = ['site_id' => 1, 'domain' => $domain, 'path' => '/', 'registered' => Date::now(), 'last_updated' => Date::now(), 'public' => 1]; $this->haveInDatabase($this->grabBlogsTableName(), $mainBlogData); } if ($this->needHtaccess) { $this->replaceFiles(); } if ($sleep) { sleep($sleep); } return $out; }