Esempio n. 1
0
 protected function _configure()
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $output = $this->_output;
     $input = $this->_input;
     $prompt = function ($key, $text, $default = null, $error = null) use($dialog, $output, $input) {
         $result = $input->getOption($key);
         if (empty($result) && !$input->getOption('no-interaction')) {
             if (!empty($default)) {
                 $text .= '(default: ' . $default . ') ';
             }
             while (strlen($result = $dialog->ask($output, '<info>' . $text . '</info>', $default)) == 0) {
             }
         } elseif (empty($result)) {
             $result = $default;
             if (empty($result)) {
                 $output->writeLn('<error>' . $error . '</error>');
                 exit(1);
             }
         }
         return $result;
     };
     $config = new Config(WWW_ROOT);
     $info = $config->getDatabaseInfo();
     $config->setDatabaseInfo(array('name' => $prompt('database-name', 'Enter the name of the database? ', @$info['name'], 'Please enter the database name'), 'user' => $prompt('database-user', 'Enter the database user? ', @$info['user'], 'Please enter the database user'), 'password' => $prompt('database-password', 'Enter the database password? ', @$info['password'], 'Please enter the database password'), 'host' => $prompt('database-host', 'Enter the database host address? ', '127.0.0.1', @$info['host']), 'port' => $prompt('database-port', 'Enter the database port? ', '3306', @$info['port']), 'prefix' => $prompt('database-prefix', 'Enter a prefix for the tables in the database? ', 'jos_', @$info['prefix'])));
     define('DS', DIRECTORY_SEPARATOR);
     define('_JEXEC', 1);
     define('JPATH_BASE', WWW_ROOT);
     define('JPATH_ROOT', JPATH_BASE);
     define('JPATH_SITE', JPATH_ROOT);
     define('JPATH_CONFIGURATION', JPATH_ROOT);
     define('JPATH_ADMINISTRATOR', JPATH_ROOT . '/administrator');
     define('JPATH_XMLRPC', JPATH_ROOT . '/xmlrpc');
     define('JPATH_LIBRARIES', JPATH_ROOT . '/libraries');
     define('JPATH_PLUGINS', JPATH_ROOT . '/plugins');
     define('JPATH_INSTALLATION', JPATH_ROOT . '/installation');
     define('JPATH_THEMES', JPATH_BASE . '/templates');
     define('JPATH_CACHE', JPATH_BASE . '/cache');
     include_once JPATH_LIBRARIES . '/joomla/import.php';
     require_once 'Console/Installer/Helper.php';
     $output->writeLn('<info>connecting to database...</info>');
     $errors = array();
     $database = $config->getDatabaseInfo();
     $db = \JInstallationHelper::getDBO('mysqli', $database['host'] . ':' . $database['port'], $database['user'], $database['password'], $database['name'], $database['prefix'], false);
     if ($db instanceof \JException) {
         $output->writeLn('<error>' . $db->toString() . '</error>');
         exit(1);
     }
     $db_exists = \JInstallationHelper::databaseExists($db, $database['name']);
     $dump_file = null;
     if ($input->getOption('database-dump')) {
         $dump_file = realpath($input->getOption('database-dump'));
     }
     if ($db_exists && $input->getOption('drop-database')) {
         $output->writeLn('<fg=red>Dropping existing database...</fg=red>');
         \JInstallationHelper::deleteDatabase($db, $database['name'], $database['prefix'], $errors);
         $db_exists = false;
     }
     if (!$db_exists) {
         $output->writeLn('<info>Creating new database...</info>');
         \JInstallationHelper::createDatabase($db, $database['name'], true);
         $db->select($database['name']);
         $sql_files = $dump_file ? array($dump_file) : array_map(function ($file) {
             return $file = ANAHITA_ROOT . "/vendor/joomla/installation/sql/{$file}";
         }, array("schema.sql", "data.sql"));
         $output->writeLn('<info>Populating database...</info>');
         array_walk($sql_files, function ($file) use($db) {
             \JInstallationHelper::populateDatabase($db, $file, $errors);
         });
     }
     jimport('joomla.user.helper');
     $config->secret = \JUserHelper::genRandomPassword(32);
     //exec("rm -rf ".JPATH_ROOT."/installation");
     $config->save();
     $output->writeLn("<info>Congratulations you're done.</info>");
     if (!$db_exists && !$dump_file) {
         $output->writeLn("<info>The first person who registers for an account becomes the Super Administrator. Point your browser to http://yoursite/people/signup and create a new account.</info>");
     }
 }
Esempio n. 2
0
            $cmd .= " | sed -e 's/`{$config->prefix}/`#__/'";
        }
        if ($file) {
            @mkdir(dirname($file), 0755, true);
            system("{$cmd} > {$file}");
        } else {
            passthru($cmd);
        }
    });
}
$console->register('db:load')->setDescription('Load data from a sql file into the database')->setDefinition(array(new InputArgument('file', InputArgument::REQUIRED, 'The output file')))->setCode(function (InputInterface $input, OutputInterface $output) use($console) {
    $file = realpath($input->getArgument('file'));
    if (!file_exists($file)) {
        throw new \Exception("File '{$file}' doesn't exists");
    }
    require_once 'Console/Installer/Helper.php';
    $console->loadFramework();
    $config = new Config(WWW_ROOT);
    $database = $config->getDatabaseInfo();
    $errors = array();
    $db = \JInstallationHelper::getDBO('mysqli', $database['host'] . ':' . $database['port'], $database['user'], $database['password'], $database['name'], $database['prefix'], true);
    if ($db instanceof \JException) {
        $output->writeLn('<error>' . $db->toString() . '</error>');
        exit(1);
    }
    if ($input->getOption('drop-tables')) {
        \JInstallationHelper::deleteDatabase($db, $database['name'], $database['prefix'], $errors);
    }
    $output->writeLn('<info>Loading data. This may take a while...</info>');
    \JInstallationHelper::populateDatabase($db, $file, $errors);
});