Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions module/VuFind/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,12 @@
'Search2/Versions',
'Summon/Advanced', 'Summon/FacetList', 'Summon/Home', 'Summon/Search',
'Tag/Home',
'Upgrade/Home', 'Upgrade/FixAnonymousTags', 'Upgrade/FixDuplicateTags',
'Upgrade/ConfirmDeprecatedColumns',
'Upgrade/FixAnonymousTags', 'Upgrade/FixDuplicateTags',
'Upgrade/FixConfig', 'Upgrade/FixDatabase', 'Upgrade/FixMetadata',
'Upgrade/GetDBCredentials', 'Upgrade/GetDbEncodingPreference',
'Upgrade/GetSourceDir', 'Upgrade/GetSourceVersion', 'Upgrade/Reset',
'Upgrade/ShowSQL', 'Upgrade/CriticalFixBlowfish',
'Upgrade/GetSourceDir', 'Upgrade/GetSourceVersion', 'Upgrade/Home',
'Upgrade/Reset', 'Upgrade/ShowSQL', 'Upgrade/CriticalFixBlowfish',
'Upgrade/CriticalFixInsecureDatabase',
'Web/Home', 'Web/FacetList', 'Web/Results',
'Worldcat/Advanced', 'Worldcat/Home', 'Worldcat/Search'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "search" DROP COLUMN "folder_id";

2 changes: 0 additions & 2 deletions module/VuFind/sql/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ CREATE TABLE `search` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL DEFAULT '0',
`session_id` varchar(128) DEFAULT NULL,
`folder_id` int(11) DEFAULT NULL,
`created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`title` varchar(20) DEFAULT NULL,
`saved` tinyint(1) NOT NULL DEFAULT '0',
Expand All @@ -146,7 +145,6 @@ CREATE TABLE `search` (
`notification_base_url` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `folder_id` (`folder_id`),
KEY `session_id` (`session_id`),
KEY `notification_frequency` (`notification_frequency`),
KEY `notification_base_url` (`notification_base_url`(190)),
Expand Down
2 changes: 0 additions & 2 deletions module/VuFind/sql/pgsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ CREATE TABLE search (
id BIGSERIAL,
user_id int NOT NULL DEFAULT '0',
session_id varchar(128),
folder_id int DEFAULT NULL,
created timestamp NOT NULL DEFAULT '1970-01-01 00:00:00',
title varchar(20) DEFAULT NULL,
saved boolean NOT NULL DEFAULT '0',
Expand All @@ -104,7 +103,6 @@ notification_base_url varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (id)
);
CREATE INDEX search_user_id_idx ON search (user_id);
CREATE INDEX search_folder_id_idx ON search (folder_id);
CREATE INDEX session_id_idx ON search (session_id);
CREATE INDEX notification_frequency_idx ON search (notification_frequency);
CREATE INDEX notification_base_url_idx ON search (notification_base_url);
Expand Down
50 changes: 50 additions & 0 deletions module/VuFind/src/VuFind/Controller/Plugin/DbUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ class DbUpgrade extends AbstractPlugin
*/
protected $tableInfo = false;

/**
* Deprecated columns, keyed by table name
*
* @var array
*/
protected $deprecatedColumns = [
'search' => ['folder_id'],
];

/**
* Given a SQL file, parse it for table creation commands.
*
Expand Down Expand Up @@ -454,6 +463,28 @@ public function createMissingTables($tables, $logsql = false)
return $sqlcommands;
}

/**
* Remove deprecated columns based on the output of getDeprecatedColumns().
*
* @param array $details Output of getDeprecatedColumns()
* @param bool $logsql Should we return the SQL as a string rather than
* execute it?
*
* @throws \Exception
* @return string SQL if $logsql is true, empty string otherwise
*/
public function removeDeprecatedColumns($details, $logsql = false)
{
$sqlcommands = '';
foreach ($details as $table => $columns) {
foreach ($columns as $column) {
$query = "ALTER TABLE `$table` DROP COLUMN `$column`;";
$sqlcommands .= $this->query($query, $logsql);
}
}
return $sqlcommands;
}

/**
* Get a list of missing columns in the database tables (associative array,
* key = table name, value = array of missing column definitions).
Expand Down Expand Up @@ -909,6 +940,25 @@ public function columnIsMissing($column, $missing)
return false;
}

/**
* Get a list of deprecated columns found in the database.
*
* @return array
*/
public function getDeprecatedColumns()
{
$result = [];
foreach ($this->deprecatedColumns as $table => $columns) {
$tableData = $this->getTableColumns(($table));
foreach ($columns as $column) {
if (isset($tableData[$column])) {
$result[$table] = array_merge($result[$table] ?? [], [$column]);
}
}
}
return $result;
}

/**
* Get a list of changed columns in the database tables (associative array,
* key = table name, value = array of column name => new data type).
Expand Down
42 changes: 42 additions & 0 deletions module/VuFind/src/VuFind/Controller/UpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,31 @@ protected function upgradeMySQL($adapter)
->setAdapter($adapter)
->loadSql(APPLICATION_PATH . '/module/VuFind/sql/mysql.sql');

// Check for deprecated columns. We prompt the user for action on this, so
// let's get that settled before doing further work.
$deprecatedColumns = $this->dbUpgrade()->getDeprecatedColumns();
if (!empty($deprecatedColumns)) {
if (!empty($this->session->deprecatedColumnsAction)) {
if ($this->session->deprecatedColumnsAction === 'delete') {
// Only manipulate DB if we're not in logging mode:
if (!$this->logsql) {
if (!$this->hasDatabaseRootCredentials()) {
return $this->forwardTo('Upgrade', 'GetDbCredentials');
}
$this->dbUpgrade()->setAdapter($this->getRootDbAdapter());
$this->session->warnings->append(
"Removed deprecated column(s) from table(s): "
. implode(', ', array_keys($deprecatedColumns))
);
}
$sql .= $this->dbUpgrade()
->removeDeprecatedColumns($deprecatedColumns, $this->logsql);
}
} else {
return $this->forwardTo('Upgrade', 'ConfirmDeprecatedColumns');
}
}

// Check for missing tables. Note that we need to finish dealing with
// missing tables before we proceed to the missing columns check, or else
// the missing tables will cause fatal errors during the column test.
Expand Down Expand Up @@ -597,6 +622,23 @@ public function showsqlAction()
return $this->createViewModel(['sql' => $this->session->sql]);
}

/**
* Prompt the user to confirm removal of deprecated columns.
*
* @return mixed
*/
public function confirmdeprecatedcolumnsAction()
{
if ($action = $this->params()->fromQuery('action')) {
if ($action === 'keep' || $action === 'delete') {
$this->session->deprecatedColumnsAction = $action;
return $this->redirect()->toRoute('upgrade-fixdatabase');
}
}
$deprecated = $this->dbUpgrade()->getDeprecatedColumns();
return $this->createViewModel(compact('deprecated'));
}

/**
* Prompt the user for database credentials.
*
Expand Down
1 change: 0 additions & 1 deletion module/VuFind/src/VuFind/Db/Row/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
* @property int $id
* @property int $user_id
* @property ?string $session_id
* @property ?int $folder_id
* @property string $created
* @property ?string $title
* @property int $saved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ protected function getMockNotifications(
'id' => 1,
'user_id' => 2,
'session_id' => null,
'folder_id' => null,
'created' => '2000-01-01 00:00:00',
'title' => null,
'saved' => 1,
Expand Down
19 changes: 19 additions & 0 deletions themes/bootstrap3/templates/upgrade/confirmdeprecatedcolumns.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php $this->headTitle($this->translate('Deprecated database columns detected')) ?>

<h2>Deprecated database columns detected</h2>

<div class="alert alert-info">
Your database contains one or more columns that are no longer used, and which should not contain any useful information.
</div>

<table class="table table-striped">
<tr><th scope="col">Table</th><th scope="col">Column(s)</th></tr>
<?php foreach ($deprecated as $table => $columns): ?>
<tr><td><?=$this->escapeHtml($table)?></td><td><?=$this->escapeHtml(implode(', ', $columns))?></td></tr>
<?php endforeach; ?>
</table>

<p><b>RECOMMENDED:</b> You can <a class="btn btn-default" href="<?=$this->url('upgrade-confirmdeprecatedcolumns')?>?action=delete">remove the columns</a>.</p>

<p>Alternatively, if you are using these columns for some reason (e.g. in local custom code), you can choose to <a class="btn btn-default" href="<?=$this->url('upgrade-confirmdeprecatedcolumns')?>?action=keep">keep the columns</a>.</p>