protected function execute(InputInterface $input, OutputInterface $output) { $env = Validators::validateEnv($input->getOption('env')); $_SERVER['DOCUMENT_ROOT'] = getcwd(); $_SERVER['SERVER_PROTOCOL'] = 'http'; $_SERVER['HTTP_HOST'] = $this->skeleton->get('deploy.%s.web.host', $env); define('WP_ROOT', $this->skeleton->getWebRoot() . '/'); define('WP_INSTALLING', true); require WP_ROOT . 'wp-load.php'; require WP_ROOT . 'wp-admin/includes/admin.php'; require WP_ROOT . 'wp-admin/includes/upgrade.php'; if (is_blog_installed()) { $output->writeln('<error>Already installed.</error>'); return 1; } $output->write('Installing...'); $result = wp_install($this->skeleton->get('name'), $this->skeleton->get('wordpress.%s.admin.user', $env), $this->skeleton->get('wordpress.%s.admin.email', $env), true, '', $this->skeleton->get('wordpress.%s.admin.password', $env)); if (is_wp_error($result)) { throw new \Exception($result); } update_option('db_version', $wp_db_version); update_option('db_upgraded', true); $output->writeln('<info>DONE</info>'); $output->writeln(sprintf("\nLogin as <info>%s</info> with the password <info>%s</info>", $this->skeleton->get('wordpress.%s.admin.user', $env), $this->skeleton->get('wordpress.%s.admin.password', $env))); }
protected function execute(InputInterface $input, OutputInterface $output) { $env = Validators::validateEnv($input->getOption('env')); // Internal WordPress connection details $wpName = $this->skeleton->get('wordpress.%s.db.name', $env); $wpUser = $this->skeleton->get('wordpress.%s.db.user', $env); $wpPassword = $this->skeleton->get('wordpress.%s.db.password', $env); $wpHost = $this->skeleton->get('wordpress.%s.db.host', $env); // Database admin user $dbUser = $this->skeleton->get('deploy.%s.db.user', $env); $dbPassword = $this->skeleton->get('deploy.%s.db.password', $env); // External host name $webHost = $this->skeleton->get('deploy.%s.web.host', $env); // Grant access to WP database for WP user + password $commands = array(sprintf('CREATE DATABASE IF NOT EXISTS %s', $wpName), sprintf('GRANT ALL ON %s.* TO %s@%s IDENTIFIED BY %s', $wpName, escapeshellarg($wpUser), escapeshellarg('%'), escapeshellarg($wpPassword)), sprintf('GRANT ALL ON %s.* TO %s@%s IDENTIFIED BY %s', $wpName, escapeshellarg($wpUser), escapeshellarg($wpHost), escapeshellarg($wpPassword)), sprintf('GRANT ALL ON %s.* TO %s@%s IDENTIFIED BY %s', $wpName, escapeshellarg($wpUser), escapeshellarg($webHost), escapeshellarg($wpPassword)), 'FLUSH PRIVILEGES'); // Use database admin for granting access foreach ($commands as $command) { $wrapper = sprintf('mysql --host=%s --user=%s --password=%s --execute=%s', escapeshellarg($wpHost), escapeshellarg($dbUser), escapeshellarg($dbPassword), escapeshellarg($command)); $output->write(sprintf('Running <info>%s</info>...', $wrapper)); passthru($wrapper, $error); if ($error) { $output->writeln('<error>FAILED</error>'); return 1; } else { $output->writeln('<comment>SUCCESS</comment>'); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $env = Validators::validateEnv($input->getOption('env')); $host = $this->skeleton->get(sprintf('deploy.%s.web.host', $env)); $url = sprintf('http://%s/', $host); $output->writeln(sprintf('Opening <info>%s</info>...', $url)); passthru("open {$url}"); }
protected function execute(InputInterface $input, OutputInterface $output) { $env = Validators::validateEnv($input->getOption('env')); $root = $this->skeleton->getWebRoot(); $stylesheet = $input->getOption('theme') ?: $this->skeleton->get('domain'); require $root . '/wp-load.php'; $output->write(sprintf('Activating theme <comment>%s</comment>...', $stylesheet)); switch_theme('_s', $stylesheet); $output->writeln('<info>DONE</info>'); }
protected function execute(InputInterface $input, OutputInterface $output) { $env = Validators::validateEnv($input->getOption('env')); $root = $this->skeleton->getWebRoot(); $plugins = $this->skeleton->get(sprintf('wordpress.%s.plugins', $env)); require $root . '/wp-load.php'; require ABSPATH . 'wp-admin/includes/admin.php'; require ABSPATH . 'wp-admin/includes/plugin-install.php'; foreach ($plugins as $slug => $version) { $plugin = plugins_api('plugin_information', array('slug' => $slug)); if (is_wp_error($plugin)) { throw new \Exception('Could not get plugin information for ' . $slug); } if ($version) { list($prefix) = explode($slug, $plugin->download_link); $link = sprintf('%s%s.%s.zip', $prefix, $slug, $version); $response = wp_remote_head($link); if (!isset($response['response']['code']) || $response['response']['code'] != 200) { throw new \Exception('Unable to verify ' . $link); } $plugin->download_link = $link; $plugin->version = $version; } require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $status = install_plugin_install_status($plugin); $upgrader = new \Plugin_Upgrader(new UpgraderSkin($output)); $current = current(get_plugins("/{$slug}")); switch ($status['status']) { case 'install': $output->write(sprintf('Installing <info>%s</info> v<comment>%s</comment>', $plugin->name, $plugin->version)); $upgrader->install($plugin->download_link); break; case 'update_available': if ($plugin->version == $current['Version']) { $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $plugin->version)); } else { $output->write(sprintf('Upgrading <info>%s</info> from <comment>%s</comment> to <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version)); $file = sprintf('%s/%s', $slug, key(get_plugins("/{$slug}"))); $upgrader->upgrade($file); } break; case 'latest_installed': $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $current['Version'])); break; case 'newer_installed': $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is installed & newer than <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version)); break; } } if ($plugins) { $output->writeln(sprintf('<info>Activate plugins in the WordPress Admin</info>', $plugin->name)); } }
protected function execute(InputInterface $input, OutputInterface $output) { $env = Validators::validateEnv($input->getOption('env')); $path = sprintf('%s/backups/%s.sql.gz', $this->skeleton->getRoot(), date('Y-m-d.his')); $command = sprintf('mysqldump -u%s -p%s -h%s --opt --databases %s | sed %s | gzip --rsyncable > %s', escapeshellarg($this->skeleton->get('wordpress.%s.db.user', $env)), escapeshellarg($this->skeleton->get('wordpress.%s.db.password', $env)), escapeshellarg($this->skeleton->get('wordpress.%s.db.host', $env)), escapeshellarg($this->skeleton->get('wordpress.%s.db.name', $env)), escapeshellarg(sprintf('s/%s/skeleton_backup/g', $this->skeleton->get('wordpress.%s.db.name', $env))), $path); @mkdir(dirname($path), 0775, true); $output->writeln(sprintf('Running <info>%s</info>', $command)); passthru($command, $error); if ($error) { $output->writeln("\t<error>FAILED</error>"); return 1; } else { $output->writeln("\t<comment>SUCCESS</comment>"); } }
public function initConfig() { if (is_file($this->configPath)) { $this->config = Yaml::parse($this->configPath); } // Ensure salts have enough spaces to prevent YAML parse errors if ($this->has('wordpress')) { foreach ($this->get('wordpress') as $env => $settings) { $property = 'wordpress.' . $env . '.salts'; $salts = Validators::validateSalts($this->get($property)); $this->set($property, $salts); } } return $this->getConfig(); }
protected function execute(InputInterface $input, OutputInterface $output) { $env = Validators::validateEnv($input->getOption('env')); // Internal WordPress connection details $wpName = $this->skeleton->get('wordpress.%s.db.name', $env); $wpHost = $this->skeleton->get('wordpress.%s.db.host', $env); // Database admin user $dbUser = $this->skeleton->get('deploy.%s.db.user', $env); $dbPassword = $this->skeleton->get('deploy.%s.db.password', $env); $command = sprintf('mysql --host=%s --user=%s --password=%s --execute=%s', escapeshellarg($wpHost), escapeshellarg($dbUser), escapeshellarg($dbPassword), escapeshellarg(sprintf('DROP DATABASE IF EXISTS %s', $wpName))); $output->writeln(sprintf('Running <info>%s</info>', $command)); passthru($command, $error); if ($error) { $output->writeln("\t<error>FAILED</error>"); return 1; } else { $output->writeln("\t<comment>SUCCESS</comment>"); } }
protected function execute(InputInterface $input, OutputInterface $output) { global $wp_importers; $env = Validators::validateEnv($input->getOption('env')); $root = $this->skeleton->getWebRoot(); define('WP_LOAD_IMPORTERS', true); require $root . '/wp-load.php'; require ABSPATH . 'wp-admin/includes/admin.php'; $error = activate_plugin('wordpress-importer/wordpress-importer.php'); if (is_wp_error($error)) { throw new \Exception('WordPress Importer could not be activated. Is it installed?'); } do_action('admin_init'); // 0 - Name, 1 = Description, 2 = Callable $importer = $wp_importers['wordpress'][2][0]; if (empty($importer)) { throw new \Exception('WordPress Importer could not be loaded'); } $url = 'https://wpcom-themes.svn.automattic.com/demo/test-data.2011-01-17.xml'; $name = basename($url); $file = sprintf('%s/%s', sys_get_temp_dir(), $name); $output->write(sprintf('Downloading <info>%s</info> to <info>%s</info>...', $url, $file)); if ($fixture = file_get_contents($url)) { $output->writeln('<comment>DONE</comment>'); } else { throw new \Exception('Unable to download ' . $file); } if (!file_put_contents($file, $fixture)) { throw new \Excception('Unable to temporarily write fixture to ' . $file); } $output->write('Importing...'); $_POST['fetch_attachments'] = true; ob_start(); @$importer->import($file); ob_end_clean(); $output->writeln('<comment>DONE</comment>'); }
private function guessSalts() { return Validators::validateSalts(file_get_contents('https://api.wordpress.org/secret-key/1.1/salt/')); }