Skip to content

Commit 2c571c7

Browse files
authored
Merge pull request #2205 from elcreator/3.5.x
[FIX] reverted prefix placeholder support and fixed login issue
2 parents 2b9a178 + 236b1ec commit 2c571c7

5 files changed

Lines changed: 36 additions & 6 deletions

File tree

core/src/Controllers/Users/LogInOut.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function simpleLogin()
8181
}
8282
}
8383
$log = new \EvolutionCMS\Legacy\LogHandler();
84-
$log->initAndWriteLog('Logged in', EvolutionCMS()->getLoginUserID('mgr'), $_SESSION['mgrShortname'], '58', '-', 'EVO');
84+
$log->initAndWriteLog('Logged in', $user->id, $user->username, '58', '-', 'EVO');
8585

8686
$id = 0;
8787
// check if we should redirect user to a web page

core/src/Database.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ public function __construct(?Container $container = null)
3434
$this->prepareNativeConfig();
3535
}
3636

37+
/**
38+
* @param string $sql
39+
* @return null|string|string[]
40+
*/
41+
public function replacePrefixPlaceholderInTableName($sql)
42+
{
43+
if (str_contains($sql, '[+prefix+]')) {
44+
$connection = $this->getConnection();
45+
$grammar = $connection->getQueryGrammar();
46+
return preg_replace_callback(
47+
'@\[\+prefix\+\](\w+)@',
48+
static function ($matches) use ($grammar) {
49+
return $grammar->wrapTable($matches[1]);
50+
},
51+
$sql
52+
);
53+
}
54+
55+
return $sql;
56+
}
57+
3758
/**
3859
* @param string $sql
3960
* @param bool $watchError
@@ -154,6 +175,11 @@ public function isConnected()
154175
return $this->conn instanceof Connection && $this->conn->getPdo() instanceof \PDO;
155176
}
156177

178+
/**
179+
* @deprecated
180+
* @since 1.4
181+
* @todo [remove@3.7] Remove in Evolution CMS 3.7
182+
*/
157183
public function insertFrom(
158184
$fields,
159185
$table,
@@ -316,15 +342,15 @@ protected function prepareFrom($data, $hasArray = false)
316342
if (\is_array($data) && $hasArray === true) {
317343
$tmp = [];
318344
foreach ($data as $table) {
319-
$tmp[] = $table;
345+
$tmp[] = $this->replacePrefixPlaceholderInTableName($table);
320346
}
321347
$data = implode(' ', $tmp);
322348
}
323349
if (!is_scalar($data) || empty($data)) {
324350
throw new Exceptions\TableNotDefinedException($data);
325351
}
326352

327-
return $data;
353+
return $this->replacePrefixPlaceholderInTableName($data);
328354
}
329355

330356
/**
@@ -458,6 +484,7 @@ public function delete($from, $where = '', $orderBy = '', $limit = '')
458484
if (!$from) {
459485
evo()->getService('ExceptionHandler')->messageQuit("Empty \$from parameters in DBAPI::delete().");
460486
} else {
487+
$from = $this->replacePrefixPlaceholderInTableName($from);
461488
$where = trim($where);
462489
$orderBy = trim($orderBy);
463490
$limit = trim($limit);
@@ -572,6 +599,7 @@ public function insert($fields, $intotable, $fromfields = "*", $fromtable = "",
572599
if (!$intotable) {
573600
evo()->getService('ExceptionHandler')->messageQuit("Empty \$intotable parameters in DBAPI::insert().");
574601
} else {
602+
$intotable = $this->replacePrefixPlaceholderInTableName($intotable);
575603
if (!is_array($fields)) {
576604
$this->query("INSERT INTO {$intotable} {$fields}");
577605
} else {
@@ -631,6 +659,7 @@ public function update($fields, $table, $where = "")
631659
if (!$table) {
632660
evo()->getService('ExceptionHandler')->messageQuit('Empty ' . $table . ' parameter in DBAPI::update().');
633661
} else {
662+
$table = $this->replacePrefixPlaceholderInTableName($table);
634663
if (is_array($fields)) {
635664
foreach ($fields as $key => $value) {
636665
if ($value === null || strtolower($value) === 'null') {
@@ -669,6 +698,7 @@ public function getTableMetaData($table)
669698
$metadata = [];
670699
$driver = evo()->getDatabase()->getConfig('driver');
671700
if (!empty($table) && is_scalar($table)) {
701+
$table = $this->replacePrefixPlaceholderInTableName($table);
672702
switch ($driver) {
673703
case 'sqlite':
674704
case 'sqlite3':

core/vendor/evolutioncms-services/user-manager/src/Services/Users/SafelyDestroyUserSessionTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait SafelyDestroyUserSessionTrait
2121

2222
protected function safelyDestroyUserSession()
2323
{
24-
if (defined('NO_SESSION')) {
24+
if (defined('NO_SESSION') && !(defined('IN_MANAGER_MODE') && IN_MANAGER_MODE)) {
2525
return;
2626
}
2727

core/vendor/evolutioncms-services/user-manager/src/Services/Users/UserLogin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function authProcess()
280280

281281
EvolutionCMS()->cleanupExpiredLocks();
282282
EvolutionCMS()->cleanupMultipleActiveUsers();
283-
if(!defined('NO_SESSION')) {
283+
if ((defined('IN_MANAGER_MODE') && IN_MANAGER_MODE) || !defined('NO_SESSION')) {
284284
$this->writeSession();
285285
}
286286
// successful login so reset fail count and update key values

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
}
130130

131131
// Initiate a new document parser
132-
$evo = evo();
132+
$GLOBALS['evo'] = $GLOBALS['modx'] = $evo = $modx = evo();
133133
$evo->minParserPasses = 1; // min number of parser recursive loops or passes
134134
$evo->maxParserPasses = 10; // max number of parser recursive loops or passes
135135
$evo->dumpSQL = false;

0 commit comments

Comments
 (0)