Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions Error/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Magento\Framework\Filesystem\Io\File as FileReader;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Phrase;
use Magento\Store\Model\StoreManager;
use Magento\Framework\Filesystem\Driver\File;

class Maintenance
{
Expand All @@ -33,21 +35,34 @@ class Maintenance
* @var FileReader
*/
private $fileReader;
/**
* @var StoreManager
*/
private $storeManager;
/**
* @var File
*/
private $fileDriver;

/**
* Maintenance constructor.
*
* @param Filesystem $filesystem
* @param FileReader $fileReader
* @param StoreManager $storeManager
* @param File $fileDriver
*/
public function __construct(
Filesystem $filesystem,
FileReader $fileReader
FileReader $fileReader,
StoreManager $storeManager,
File $fileDriver
) {
$this->filesystem = $filesystem;
$this->fileReader = $fileReader;
$objectManagerFactory = Bootstrap::createObjectManagerFactory(BP, $_SERVER);
$this->objectManager = $objectManagerFactory->create($_SERVER);
$this->storeManager = $storeManager;
$this->fileDriver = $fileDriver;
}

/**
Expand All @@ -69,11 +84,25 @@ public function renderPage()
*/
private function setTemplate()
{
$templatePath = $this->filesystem
->getDirectoryRead(DirectoryList::PUB)
->getAbsolutePath('maintenance/index.html');
$path = $this->filesystem->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath() . "maintenance/";
$store = $this->storeManager->getStore();

// Default template ([store_code].html)
$template = $path . $store->getCode() . ".html";
if (!$this->fileDriver->isExists($template)) {
// Second template ([website_code].html)
$template = $path . $store->getWebsite()->getCode() . ".html";
if (!$this->fileDriver->isExists($template)) {
// Third template (fallback.html)
$template = $path . "fallback.html";
if (!$this->fileDriver->isExists($template)) {
// Last template (index.html)
$template = $path . "index.html";
}
}
}

$template = $this->fileReader->read($templatePath);
$template = $this->fileReader->read($template);

if (!$template) {
return __('Maintenance html file not found. Upload your index.html file under pub/maintenance directory.');
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "alpine/maintenance",
"description": "Custom maintenance page from html file placed in pub/maintenance directory",
"require": {
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
"php": "^7.1.3||^8.1",
"magento/magento-composer-installer": "*",
"magento/framework": "102.0.*||103.0.*"
},
Expand Down