Skip to content

Commit

Permalink
Merge pull request #1 from lopes-vincent/improvement
Browse files Browse the repository at this point in the history
Improvement
  • Loading branch information
lopes-vincent authored Nov 30, 2016
2 parents afcf5c5 + bd154a3 commit 0676440
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.0</version>
<version>1.0.1</version>
<authors>
<author>
<name>Vincent Lopes-Vicente</name>
Expand Down
9 changes: 7 additions & 2 deletions Controller/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function viewAction()
$isInMaintenance = 1;
}

$isIndexWritable = is_writable(THELIA_WEB_DIR."index.php");
$isWebWritable = is_writable(THELIA_WEB_DIR);

return $this->render(
'maintenance/configuration',
[
Expand All @@ -48,7 +51,9 @@ public function viewAction()
'backgroundColor' => html_entity_decode($backgroundColor[1]),
'fontColor' => html_entity_decode($fontColor[1]),
'linkColor' => html_entity_decode($linkColor[1]),
'isInMaintenance' => $isInMaintenance
'isInMaintenance' => $isInMaintenance,
'isIndexWritable' => $isIndexWritable,
'isWebWritable' => $isWebWritable,
]
);
}
Expand Down Expand Up @@ -115,7 +120,7 @@ public function toggleMaintenanceAction()
if (preg_match("/\/\/⚠((.|\n)*)⚠/", $contents)) {
$newContent = preg_replace("/\/\/⚠((.|\n)*)⚠/", "", $contents);
} else {
$maintenanceTag = "**/\n\n//⚠--MAINTENANCE\nhttp_response_code(503);\ninclude('../local/modules/Maintenance/templates/maintenance.html');\ndie();\n//__⚠\n";
$maintenanceTag = "**/\n\n//⚠--MAINTENANCE\nhttp_response_code(503);\ninclude('maintenance.html');\ndie();\n//__⚠\n";
$newContent = preg_replace("/\*\*\/\n\n/i", $maintenanceTag, $contents);
}

Expand Down
16 changes: 15 additions & 1 deletion Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Maintenance;

use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Thelia\Module\BaseModule;
Expand All @@ -21,21 +22,34 @@ class Maintenance extends BaseModule
/** @var string */
const DOMAIN_NAME = 'maintenance';

const MAINTENANCE_FILE = THELIA_WEB_DIR.'maintenance.html';

/*
* You may now override BaseModuleInterface methods, such as:
* install, destroy, preActivation, postActivation, preDeactivation, postDeactivation
*
* Have fun !
*/

public function postActivation(ConnectionInterface $con = null)
{
if (!file_exists(self::MAINTENANCE_FILE)) {
copy(THELIA_MODULE_DIR . 'Maintenance' . DS . 'templates'. DS .'maintenance.html', self::MAINTENANCE_FILE);
}
}


/**
* @return SplFileInfo
*/
public static function getMaintenanceFile()
{
if (!file_exists(self::MAINTENANCE_FILE)) {
copy(THELIA_MODULE_DIR . 'Maintenance' . DS . 'templates'. DS .'maintenance.html', self::MAINTENANCE_FILE);
}

$finder = new Finder();
$finder->files()->in(THELIA_MODULE_DIR . 'Maintenance' . DS . 'templates')->name("maintenance.html");
$finder->files()->in(THELIA_WEB_DIR)->name("maintenance.html");

/** @var SplFileInfo $file */
foreach ($finder as $file) {
Expand Down
10 changes: 10 additions & 0 deletions templates/backOffice/default/maintenance/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@

<div class="row">
<div class="col-lg-12">
{if $isIndexWritable !== true}
<div class="alert alert-danger">
{intl l="The file web/index.php is not writable please change the permissions or the module will not work"}
</div>
{/if}
{if $isWebWritable !== true}
<div class="alert alert-danger">
{intl l="The directory web is not writable please change the permissions or the module will not work"}
</div>
{/if}
<h1 class="page-header">
<div class="row">
<div class="col-md-4">
Expand Down
10 changes: 5 additions & 5 deletions templates/maintenance.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<title>Maintenance</title>
<style>
body {
--background-color: /*background_color*/#251616/*background_color*/;
--font-color: /*font_color*/#d5c394/*font_color*/;
--background-color: /*background_color*/#2a3343/*background_color*/;
--font-color: /*font_color*/#d1d1d1/*font_color*/;
background-color: var(--background-color);
}
#maintenance_page {
Expand All @@ -16,18 +16,18 @@
}
#maintenance_page article { display: block; text-align: left; width: 650px; margin: 0 auto; }
#maintenance_page h1 { font-size: 50px; }
#maintenance_page a { color: /*link_color*/#ffffff/*link_color*/; text-decoration: none; }
#maintenance_page a { color: /*link_color*/#ffff8d/*link_color*/; text-decoration: none; }
#maintenance_page a:hover { color: var(--font-color); text-decoration: none; }
</style>

<div id="maintenance_page">
<article>
<h1>
<!--TITLE START-->We&rsquo;ll be back soon!<!--TITLE END-->
<!--TITLE START-->Well be back soon!<!--TITLE END-->
</h1>
<div>
<p>
<!--MESSAGE START-->Sorry for the inconvenience but we&rsquo;re performing some maintenance at the moment. If you need to you can always <a href="mailto:#">contact us</a>, otherwise we&rsquo;ll be back online shortly!<!--MESSAGE END-->
<!--MESSAGE START-->Sorry for the inconvenience but were performing some maintenance at the moment. If you need to you can always <a href="mailto:#">contact us</a>, otherwise well be back online shortly!<!--MESSAGE END-->
</p>
</div>
</article>
Expand Down

0 comments on commit 0676440

Please sign in to comment.