Skip to content

Commit 9d6767d

Browse files
authored
Merge pull request #72 from phpList/table-prefix-fix
Update "maintenance mode" queries to use $table_prefix
2 parents 4eb738f + 082db4a commit 9d6767d

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

index.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class updater
1616

1717
const DOWNLOAD_PATH = '../tmp_uploaded_update';
1818
const ELIGIBLE_SESSION_KEY = 'phplist_updater_eligible';
19+
const CONFIG_FILE = __DIR__ . '/../config/config.php';
1920

2021
private $excludedFiles = array(
2122
'dl.php',
@@ -282,7 +283,7 @@ function deleteFiles()
282283
*/
283284
function getConnection()
284285
{
285-
$standardConfig = __DIR__ . '/../config/config.php';
286+
$standardConfig = self::CONFIG_FILE;
286287

287288
if (isset($_SERVER['ConfigFile']) && is_file($_SERVER['ConfigFile'])) {
288289
include $_SERVER['ConfigFile'];
@@ -322,45 +323,68 @@ function getConnection()
322323
*/
323324
function addMaintenanceMode()
324325
{
325-
$prepStmt = $this->getConnection()->prepare("SELECT * FROM phplist_config WHERE item=?");
326+
$standardConfig = self::CONFIG_FILE;
327+
if (isset($_SERVER['ConfigFile']) && is_file($_SERVER['ConfigFile'])) {
328+
include $_SERVER['ConfigFile'];
329+
} elseif (file_exists($standardConfig)) {
330+
include $standardConfig;
331+
} else {
332+
throw new \UpdateException("Error: Cannot find config file");
333+
}
334+
if (isset($table_prefix)) {
335+
$table_name = $table_prefix . 'config';
336+
} else {
337+
$table_name = 'phplist_config';
338+
}
339+
$prepStmt = $this->getConnection()->prepare("SELECT * FROM {$table_name} WHERE item=?");
326340
$prepStmt->execute(array('update_in_progress'));
327341
$result = $prepStmt->fetch(PDO::FETCH_ASSOC);
328342
if ($result === false) {
329343
// the row does not exist => no update running
330344
$this->getConnection()
331-
->prepare('INSERT INTO phplist_config(`item`,`editable`,`value`) VALUES (?,0,?)')
345+
->prepare("INSERT INTO {$table_name}(`item`,`editable`,`value`) VALUES (?,0,?)")
332346
->execute(array('update_in_progress', 1));
333347
}
334348
if ($result['update_in_progress'] == 0) {
335349
$this->getConnection()
336-
->prepare('UPDATE phplist_config SET `value`=? WHERE `item`=?')
350+
->prepare("UPDATE {$table_name} SET `value`=? WHERE `item`=?")
337351
->execute(array(1, 'update_in_progress'));
338-
339352
} else {
340353
// the row exists and is not 0 => there is an update running
341354
return false;
342355
}
343356
$name = 'maintenancemode';
344357
$value = "Update process";
345-
$sql = "UPDATE phplist_config SET value =?, editable =? where item =? ";
358+
$sql = "UPDATE {$table_name} SET value =?, editable =? where item =? ";
346359
$this->getConnection()->prepare($sql)->execute(array($value, 0, $name));
347-
348360
}
349361

350362
/**
351363
*Clear the maintenance mode and remove the update_in_progress lock
364+
* @throws UpdateException
352365
*/
353366
function removeMaintenanceMode()
354367
{
368+
$standardConfig = self::CONFIG_FILE;
369+
if (isset($_SERVER['ConfigFile']) && is_file($_SERVER['ConfigFile'])) {
370+
include $_SERVER['ConfigFile'];
371+
} elseif (file_exists($standardConfig)) {
372+
include $standardConfig;
373+
} else {
374+
throw new \UpdateException("Error: Cannot find config file");
375+
}
376+
if (isset($table_prefix)) {
377+
$table_name = $table_prefix . 'config';
378+
} else {
379+
$table_name = 'phplist_config';
380+
}
355381
$name = 'maintenancemode';
356382
$value = '';
357-
$sql = "UPDATE phplist_config SET value =?, editable =? where item =? ";
383+
$sql = "UPDATE {$table_name} SET value =?, editable =? where item =? ";
358384
$this->getConnection()->prepare($sql)->execute(array($value, 0, $name));
359-
360385
$this->getConnection()
361-
->prepare('UPDATE phplist_config SET `value`=? WHERE `item`=?')
386+
->prepare("UPDATE {$table_name} SET `value`=? WHERE `item`=?")
362387
->execute(array(0, "update_in_progress"));
363-
364388
}
365389

366390
/**

0 commit comments

Comments
 (0)