Skip to content
Snippets Groups Projects
Commit 45b79957 authored by Chris Hallberg's avatar Chris Hallberg
Browse files

SQL printing during install.

Added click to select all support to showsql.phtml.
parent d964ab8a
No related merge requests found
...@@ -398,7 +398,7 @@ $staticRoutes = array( ...@@ -398,7 +398,7 @@ $staticRoutes = array(
'Cover/Show', 'Cover/Unavailable', 'Error/Unavailable', 'Help/Home', 'Cover/Show', 'Cover/Unavailable', 'Error/Unavailable', 'Help/Home',
'Install/Done', 'Install/FixBasicConfig', 'Install/FixCache', 'Install/Done', 'Install/FixBasicConfig', 'Install/FixCache',
'Install/FixDatabase', 'Install/FixDependencies', 'Install/FixILS', 'Install/FixDatabase', 'Install/FixDependencies', 'Install/FixILS',
'Install/FixSolr', 'Install/Home', 'Install/FixSolr', 'Install/Home', 'Install/ShowSQL',
'MyResearch/Account', 'MyResearch/CheckedOut', 'MyResearch/Delete', 'MyResearch/Account', 'MyResearch/CheckedOut', 'MyResearch/Delete',
'MyResearch/DeleteList', 'MyResearch/Edit', 'MyResearch/Email', 'MyResearch/DeleteList', 'MyResearch/Edit', 'MyResearch/Email',
'MyResearch/Export', 'MyResearch/Favorites', 'MyResearch/Fines', 'MyResearch/Export', 'MyResearch/Favorites', 'MyResearch/Fines',
...@@ -412,7 +412,8 @@ $staticRoutes = array( ...@@ -412,7 +412,8 @@ $staticRoutes = array(
'Tag/Home', 'Tag/Home',
'Upgrade/Home', 'Upgrade/FixAnonymousTags', 'Upgrade/FixConfig', 'Upgrade/Home', 'Upgrade/FixAnonymousTags', 'Upgrade/FixConfig',
'Upgrade/FixDatabase', 'Upgrade/FixMetadata', 'Upgrade/GetDBCredentials', 'Upgrade/FixDatabase', 'Upgrade/FixMetadata', 'Upgrade/GetDBCredentials',
'Upgrade/GetSourceDir', 'Upgrade/Reset', 'Upgrade/ShowSQL', 'VuDL/Record', 'Upgrade/GetSourceDir', 'Upgrade/Reset', 'Upgrade/ShowSQL',
'VuDL/Browse', 'VuDL/DSRecord', 'VuDL/Record',
'Worldcat/Advanced', 'Worldcat/Home', 'Worldcat/Search' 'Worldcat/Advanced', 'Worldcat/Home', 'Worldcat/Search'
); );
......
...@@ -298,20 +298,22 @@ class InstallController extends AbstractBase ...@@ -298,20 +298,22 @@ class InstallController extends AbstractBase
$view->dbuser = $this->params()->fromPost('dbuser', 'vufind'); $view->dbuser = $this->params()->fromPost('dbuser', 'vufind');
$view->dbhost = $this->params()->fromPost('dbhost', 'localhost'); $view->dbhost = $this->params()->fromPost('dbhost', 'localhost');
$view->dbrootuser = $this->params()->fromPost('dbrootuser', 'root'); $view->dbrootuser = $this->params()->fromPost('dbrootuser', 'root');
$skip = $this->params()->fromPost('printsql', 'nope') == 'Skip';
if (!preg_match('/^\w*$/', $view->dbname)) { if (!$skip && !preg_match('/^\w*$/', $view->dbname)) {
$this->flashMessenger()->setNamespace('error') $this->flashMessenger()->setNamespace('error')
->addMessage('Database name must be alphanumeric.'); ->addMessage('Database name must be alphanumeric.');
} else if (!preg_match('/^\w*$/', $view->dbuser)) { } else if (!$skip && !preg_match('/^\w*$/', $view->dbuser)) {
$this->flashMessenger()->setNamespace('error') $this->flashMessenger()->setNamespace('error')
->addMessage('Database user must be alphanumeric.'); ->addMessage('Database user must be alphanumeric.');
} else if (strlen($this->params()->fromPost('submit', '')) > 0) { } else if ($skip || strlen($this->params()->fromPost('submit', '')) > 0) {
$newpass = $this->params()->fromPost('dbpass'); $newpass = $this->params()->fromPost('dbpass');
$newpassConf = $this->params()->fromPost('dbpassconfirm'); $newpassConf = $this->params()->fromPost('dbpassconfirm');
if (empty($newpass) || empty($newpassConf)) { if (!$skip && (empty($newpass) || empty($newpassConf))) {
$this->flashMessenger()->setNamespace('error') $this->flashMessenger()->setNamespace('error')
->addMessage('Password fields must not be blank.'); ->addMessage('Password fields must not be blank.');
} else if ($newpass != $newpassConf) { } else if (!$skip && $newpass != $newpassConf) {
$this->flashMessenger()->setNamespace('error') $this->flashMessenger()->setNamespace('error')
->addMessage('Password fields must match.'); ->addMessage('Password fields must match.');
} else { } else {
...@@ -323,39 +325,46 @@ class InstallController extends AbstractBase ...@@ -323,39 +325,46 @@ class InstallController extends AbstractBase
$connection . '/mysql' $connection . '/mysql'
); );
try { try {
// Get SQL together
$query = 'CREATE DATABASE ' . $view->dbname; $query = 'CREATE DATABASE ' . $view->dbname;
$db->query($query, $db::QUERY_MODE_EXECUTE);
$grant = "GRANT SELECT,INSERT,UPDATE,DELETE ON " $grant = "GRANT SELECT,INSERT,UPDATE,DELETE ON "
. $view->dbname . $view->dbname
. ".* TO '{$view->dbuser}'@'{$view->dbhost}' " . ".* TO '{$view->dbuser}'@'{$view->dbhost}' "
. "IDENTIFIED BY " . $db->getPlatform()->quoteValue($newpass) . "IDENTIFIED BY " . $db->getPlatform()->quoteValue($newpass)
. " WITH GRANT OPTION"; . " WITH GRANT OPTION";
$db->query($grant, $db::QUERY_MODE_EXECUTE);
$db->query('FLUSH PRIVILEGES', $db::QUERY_MODE_EXECUTE);
$db = AdapterFactory::getAdapterFromConnectionString(
$connection . '/' . $view->dbname
);
$sql = file_get_contents( $sql = file_get_contents(
APPLICATION_PATH . '/module/VuFind/sql/mysql.sql' APPLICATION_PATH . '/module/VuFind/sql/mysql.sql'
); );
$statements = explode(';', $sql); if($skip == 'Skip') {
foreach ($statements as $current) { $omnisql = $query .";\n". $grant .";\nFLUSH PRIVILEGES;\n\n". $sql;
// Skip empty sections: $this->getRequest()->getQuery()->set('sql', $omnisql);
if (strlen(trim($current)) == 0) { return $this->forwardTo('Install', 'showsql');
continue; } else {
$db->query($query, $db::QUERY_MODE_EXECUTE);
$db->query($grant, $db::QUERY_MODE_EXECUTE);
$db->query('FLUSH PRIVILEGES', $db::QUERY_MODE_EXECUTE);
$db = AdapterFactory::getAdapterFromConnectionString(
$connection . '/' . $view->dbname
);
$statements = explode(';', $sql);
foreach ($statements as $current) {
// Skip empty sections:
if (strlen(trim($current)) == 0) {
continue;
}
$db->query($current, $db::QUERY_MODE_EXECUTE);
}
// If we made it this far, we can update the config file and
// forward back to the home action!
$string = "mysql://{$view->dbuser}:{$newpass}@"
. $view->dbhost . '/' . $view->dbname;
$config
= ConfigReader::getLocalConfigPath('config.ini', null, true);
$writer = new ConfigWriter($config);
$writer->set('Database', 'database', $string);
if (!$writer->save()) {
return $this->forwardTo('Install', 'fixbasicconfig');
} }
$db->query($current, $db::QUERY_MODE_EXECUTE);
}
// If we made it this far, we can update the config file and
// forward back to the home action!
$string = "mysql://{$view->dbuser}:{$newpass}@"
. $view->dbhost . '/' . $view->dbname;
$config
= ConfigReader::getLocalConfigPath('config.ini', null, true);
$writer = new ConfigWriter($config);
$writer->set('Database', 'database', $string);
if (!$writer->save()) {
return $this->forwardTo('Install', 'fixbasicconfig');
} }
return $this->redirect()->toRoute('install-home'); return $this->redirect()->toRoute('install-home');
} catch (\Exception $e) { } catch (\Exception $e) {
...@@ -366,6 +375,16 @@ class InstallController extends AbstractBase ...@@ -366,6 +375,16 @@ class InstallController extends AbstractBase
} }
return $view; return $view;
} }
protected function showsqlAction() {
$continue = $this->params()->fromPost('continue', 'nope');
if ($continue == 'Next') {
return $this->redirect()->toRoute('install-home');
}
return $this->createViewModel(array('sql' => $this->params()->fromQuery('sql')));
return $view;
}
/** /**
* Check if ILS configuration is appropriate. * Check if ILS configuration is appropriate.
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
<tr><td>MySQL Host: </td><td><input type="text" name="dbhost" value="<?=$this->escapeHtml($this->dbhost)?>"/></td></tr> <tr><td>MySQL Host: </td><td><input type="text" name="dbhost" value="<?=$this->escapeHtml($this->dbhost)?>"/></td></tr>
<tr><td>MySQL Root User: </td><td><input type="text" name="dbrootuser" value="<?=$this->escapeHtml($this->dbrootuser)?>"/></td></tr> <tr><td>MySQL Root User: </td><td><input type="text" name="dbrootuser" value="<?=$this->escapeHtml($this->dbrootuser)?>"/></td></tr>
<tr><td>MySQL Root Password: </td><td><input type="password" name="dbrootpass" value=""/></td></tr> <tr><td>MySQL Root Password: </td><td><input type="password" name="dbrootpass" value=""/></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="<?=$this->transEsc('Submit') ?>" /></td></tr> <tr><td width="50%"></td><td><input type="submit" name="submit" value="<?=$this->transEsc('Submit') ?>" /></td></tr>
<tr><td>If you don't have the credentials or you wish to print the SQL out :</td><td>Click here to <input type="submit" name="printsql" value="Skip"> credentials.</td></tr>
</tbody> </tbody>
</table> </table>
</form> </form>
\ No newline at end of file
<?
// Set page title.
$this->headTitle($this->translate('Install VuFind'));
// Set up breadcrumbs:
$this->layout()->breadcrumbs = '<em>' . $this->transEsc('Install VuFind') . '</em>';
?>
<style>
.pre {
width:90%;
overflow-y:visible;
padding:8px;
margin:1em 2em;
background:#EEE;
border:1px dashed #CCC;
white-space:pre-wrap;
}
</style>
<h1><?=$this->transEsc('Install VuFind')?></h1>
<?=$this->flashmessages()?>
<p>Save this SQL somewhere safe:</p>
<textarea class="pre" rows="20" readonly onClick="this.select()"><?=trim($this->sql) ?></textarea>
<form method="POST" action="<?=$this->url('install-showsql')?>">
<input type="submit" name="continue" value="Next">
</form>
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// Set up styles: // Set up styles:
$this->headstyle()->appendStyle( $this->headstyle()->appendStyle(
"pre {\n" "pre {\n"
. " padding:8px; margin:1em 2em; background:#EEE; border:1px dashed #CCC;\n" . " white-space:pre-line; width:90%; overflow-y:visible; padding:8px; margin:1em 2em; background:#EEE; border:1px dashed #CCC;\n"
. "}\n" . "}\n"
); );
?> ?>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<?=$this->flashmessages()?> <?=$this->flashmessages()?>
<p>These SQL statements can be used to manually upgrade your database:</p> <p>These SQL statements can be used to manually upgrade your database:</p>
<pre><?=$this->escapeHtml(trim($this->sql))?></pre> <textarea class="pre" rows="20" readonly onClick="this.select()"><?=trim($this->sql) ?></textarea>
<form method="post" action="<?=$this->url('upgrade-showsql')?>"> <form method="post" action="<?=$this->url('upgrade-showsql')?>">
<input type="submit" name="continue" value="Next" /> <input type="submit" name="continue" value="Next" />
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment