Skip to content

Commit 17be29d

Browse files
authored
[5.1] Guided tours welcome performance (#43166)
1 parent 4ecd0b1 commit 17be29d

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

administrator/components/com_guidedtours/src/Model/TourModel.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ protected function setStepsLanguage(int $id, string $language = '*'): bool
510510
* @param int $id Id of a tour
511511
* @param int $autostart The autostart value of a tour
512512
*
513-
* @since 5.0.0
513+
* @since __DEPLOY_VERSION__
514514
*/
515515
public function setAutostart($id, $autostart)
516516
{
@@ -526,4 +526,36 @@ public function setAutostart($id, $autostart)
526526
$db->setQuery($query);
527527
$db->execute();
528528
}
529+
530+
/**
531+
* Retrieve a tour's autostart value
532+
*
533+
* @param string $uid the uid of a tour
534+
*
535+
* @since __DEPLOY_VERSION__
536+
*/
537+
public function isAutostart($uid)
538+
{
539+
$db = $this->getDatabase();
540+
541+
$query = $db->getQuery(true)
542+
->select($db->quoteName('autostart'))
543+
->from($db->quoteName('#__guidedtours'))
544+
->where($db->quoteName('published') . ' = 1')
545+
->where($db->quoteName('uid') . ' = :uid')
546+
->bind(':uid', $uid, ParameterType::STRING);
547+
548+
$db->setQuery($query);
549+
550+
try {
551+
$result = $db->loadResult();
552+
if ($result === null) {
553+
return false;
554+
}
555+
} catch (\RuntimeException $e) {
556+
return false;
557+
}
558+
559+
return $result;
560+
}
529561
}

plugins/system/guidedtours/src/Extension/GuidedTours.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,20 @@ public function onBeforeCompileHead()
161161

162162
// Temporary solution to auto-start the welcome tour
163163
if ($app->getInput()->getCmd('option', 'com_cpanel') === 'com_cpanel') {
164-
$tour = $this->getTour('joomla-welcome');
164+
$factory = $app->bootComponent('com_guidedtours')->getMVCFactory();
165165

166-
if ($tour && $tour->autostart) {
167-
$doc->addScriptOptions('com_guidedtours.autotour', $tour->id);
166+
$tourModel = $factory->createModel(
167+
'Tour',
168+
'Administrator',
169+
['ignore_request' => true]
170+
);
168171

169-
// Set autostart to '0' to avoid it to autostart again
170-
$factory = $app->bootComponent('com_guidedtours')->getMVCFactory();
172+
if ($tourModel->isAutostart('joomla-welcome')) {
173+
$tour = $this->getTour('joomla-welcome');
171174

172-
$tourModel = $factory->createModel(
173-
'Tour',
174-
'Administrator',
175-
['ignore_request' => true]
176-
);
175+
$doc->addScriptOptions('com_guidedtours.autotour', $tour->id);
177176

177+
// Set autostart to '0' to avoid it to autostart again
178178
$tourModel->setAutostart($tour->id, 0);
179179
}
180180
}

0 commit comments

Comments
 (0)