Skip to content

Commit

Permalink
Show a hint in the install tool if there are old custom templates (see
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 3, 2018
1 parent 7f4a62c commit a7a459b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## DEV

* Show a hint in the install tool if there are old custom templates (see #21).
* Make the ID of the subscription modules unique (see #40).

## 4.4.23 (2018-08-28)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,25 @@ p {
}
#sql_message {
margin-bottom:1em;
padding:1em;
padding:.2em 1em 1.2em;
background:#ffc;
border:1px solid #fc0;
}
#sql_message > :last-child {
margin-bottom:0;
}
#sql_message h3 {
padding:1em 0;
}
#sql_message ul {
margin:0 0 1em 2em;
}
#sql_message li {
list-style:initial;
line-height:1.4;
}
#sql_message a {
text-decoration:underline;
}
#sql_table {
margin:-9px 0 0;
Expand Down
58 changes: 58 additions & 0 deletions installation-bundle/src/Database/Version400Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,63 @@ public function run()
WHERE
type = 'headline'
");

$this->checkCustomTemplates();
}

private function checkCustomTemplates()
{
static $mapper = [
'tl_article' => [
'mod_article_plain' => 'mod_article',
'mod_article_teaser' => 'mod_article',
],
'tl_content' => [
'ce_hyperlink_image' => 'ce_hyperlink',
],
'tl_module' => [
'mod_login_1cl' => 'mod_login',
'mod_login_2cl' => 'mod_login',
'mod_logout_1cl' => 'mod_login',
'mod_logout_2cl' => 'mod_login',
'mod_search_advanced' => 'mod_search',
'mod_search_simple' => 'mod_search',
'mod_eventmenu_year' => 'mod_eventmenu',
'mod_newsmenu_day' => 'mod_newsmenu',
'mod_newsmenu_year' => 'mod_newsmenu',
],
];

foreach ($mapper as $table => $templates) {
$stmt = $this->connection->prepare("
SELECT
*
FROM
$table
WHERE
customTpl = :template
");

foreach ($templates as $old => $new) {
$stmt->bindValue(':template', $old);
$stmt->execute();

if (false !== ($row = $stmt->fetch(\PDO::FETCH_OBJ))) {
$this->addMessage(sprintf('<li>%s.%s → %s</li>', $table, $row->id, $old));
}
}
}

if ($this->hasMessage()) {
$translator = $this->container->get('translator');

$this->prependMessage(sprintf(
'<h3>%s</h3><p>%s</p><ul>',
$translator->trans('old_templates'),
$translator->trans('old_templates_begin')
));

$this->addMessage(sprintf('</ul><p>%s</p>', $translator->trans('old_templates_end')));
}
}
}
9 changes: 7 additions & 2 deletions installation-bundle/src/Database/Version447Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ public function run()
if ($this->hasMessage()) {
$translator = $this->container->get('translator');

$this->prependMessage(sprintf('<p>%s</p><ul>', $translator->trans('duplicate_subscriptions')));
$this->addMessage(sprintf('</ul><p>%s</p>', $translator->trans('duplicates_purged')));
$this->prependMessage(sprintf(
'<h3>%s</h3><p>%s</p><ul>',
$translator->trans('duplicate_subscriptions'),
$translator->trans('duplicate_subscriptions_begin')
));

$this->addMessage(sprintf('</ul><p>%s</p>', $translator->trans('duplicate_subscriptions_end')));
}

$this->connection->query('
Expand Down
20 changes: 18 additions & 2 deletions installation-bundle/src/Resources/translations/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,28 @@
</trans-unit>
<trans-unit id="73">
<source>duplicate_subscriptions</source>
<target>Duplicate newsletter subscriptions found:</target>
<target>Duplicate subscriptions</target>
</trans-unit>
<trans-unit id="74">
<source>duplicates_purged</source>
<source>duplicate_subscriptions_begin</source>
<target>Duplicate newsletter subscriptions found:</target>
</trans-unit>
<trans-unit id="75">
<source>duplicate_subscriptions_end</source>
<target>The duplicate entries have been purged automatically. A backup of the original subscriptions has been stored in &lt;code&gt;tl_newsletter_recipients_backup&lt;/code&gt;.</target>
</trans-unit>
<trans-unit id="76">
<source>old_templates</source>
<target>Old templates in use</target>
</trans-unit>
<trans-unit id="77">
<source>old_templates_begin</source>
<target>The following elements are using old custom templates:</target>
</trans-unit>
<trans-unit id="78">
<source>old_templates_end</source>
<target>Check out the &lt;a href="https://github.com/contao/contao/blob/master/UPGRADE.md#template-name-changes" target="_blank" rel="noopener noreferrer"&gt;template name changes&lt;/a&gt; and update your installation accordingly.</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit a7a459b

Please sign in to comment.