/** * Create a new WordPress website from scratch * * @Given /^\w+ have a vanilla wordpress installation$/ */ public function installWordPress(TableNode $table = null) { global $wp_rewrite; $name = "admin"; $email = "*****@*****.**"; $password = "******"; $username = "******"; if ($table) { $hash = $table->getHash(); $row = $hash[0]; $name = $row["name"]; $username = $row["username"]; $email = $row["email"]; $password = $row["password"]; } $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";"))); \PHPUnit_Framework_Assert::assertTrue($value); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install($name, $username, $email, true, '', $password); //This is a bit of a hack, we don't care about the notification e-mails here so clear the inbox //we run the risk of deleting stuff we want! $this->inboxFactory->getInbox($email)->clearInbox(); $wp_rewrite->init(); $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); }
/** * Create a new WordPress website from scratch * * @Given /^\w+ have|has a vanilla wordpress installation$/ */ public function installWordPress(TableNode $table = null) { $name = "admin"; $email = "*****@*****.**"; $password = "******"; $username = "******"; if ($table) { $row = $table->getHash()[0]; $name = $row["name"]; $username = $row["username"]; $email = $row["email"]; $password = $row["password"]; } $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";"))); assertTrue($value); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install($name, $username, $email, true, '', $password); }
/** * Create a new WordPress website from scratch * * @Given /^\w+ have|has a vanilla wordpress installation$/ */ public function installWordPress(TableNode $table = null) { global $wp_rewrite; $name = "admin"; $email = "*****@*****.**"; $password = "******"; $username = "******"; if ($table) { $hash = $table->getHash(); $row = $hash[0]; $name = $row["name"]; $username = $row["username"]; $email = $row["email"]; $password = $row["password"]; } $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";"))); assertTrue($value); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install($name, $username, $email, true, '', $password); $wp_rewrite->init(); $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); }
/** * Run the actual query with deadlock checks * @return bool|object * @throws TransactionDeadlockException */ protected function runQuery() { $numRetry = 0; do { $returned = $this->isSingleQuery ? $this->connection->query($this->sqlQuery) : $this->connection->multi_query($this->sqlQuery); if ($returned) { break; } $errno = mysqli_errno($this->connection); if ($errno != '1205' && $errno != '1213') { break; } // innodb deadlock; retry or if in transaction throw exception if ($this->isTransaction) { $this->rollback(); throw new TransactionDeadlockException('Transaction deadlock.'); } if ($numRetry == 5) { sleep(1); } ++$numRetry; } while ($numRetry < 10); return $returned; }
/** * generateDatabase * Execute TickiSql for application * @param string $dir The application's root directory. * @param \Composer\IO\IOInterface $io IO interface to write to console. * @return void */ public static function generateDatabase($rootDir, $io) { $installDatabase = $io->ask('Install Ticki database automatically ? </info> [<comment>Y,n</comment>]? ', 'Y', 'Y'); if ($installDatabase !== 'N' || $installDatabase !== 'n') { $TickiConfig = $rootDir . '/config/schema/Ticki.sql'; $content = file_get_contents($TickiConfig); $content = str_replace('_DATABASE_', static::$_databaseName, $content); $result = file_put_contents($TickiConfig, $content); if (!$result) { $io->write('Unable to update Database value on sql file.'); return; } $mysqli = null; if (static::$_port) { $mysqli = new Mysqli(static::$_hostName, static::$_userName, static::$_password, "", static::$_port); } else { $mysqli = new Mysqli(static::$_hostName, static::$_userName, static::$_password); } if ($mysqli->connect_errno) { $io->write("<error>Connection fail : " . $mysqli->connect_error . '</error>'); return; } if (!$mysqli->multi_query($content)) { $io->write('<error>Unable to install database, do it manually please</error>'); } $mysqli->close(); $io->write('<info>Set up database Ticki is a success.</info>'); } }
/** * flush the database if specified by flush_database parameter */ public function flushDatabase() { if ($this->wordpressParams['flush_database']) { $connection = $this->wordpressParams['connection']; $mysqli = new \Mysqli('localhost', $connection['username'], $connection['password'], $connection['db']); $result = $mysqli->multi_query("DROP DATABASE IF EXISTS {$connection['db']}; CREATE DATABASE {$connection['db']};"); } }