WIP : Install wizard : step 2 file permission
This commit is contained in:
@@ -26,12 +26,14 @@ use Thelia\Install\CheckPermission;
|
||||
|
||||
/**
|
||||
* Class InstallController
|
||||
*
|
||||
* @package Thelia\Controller\Install
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*/
|
||||
class InstallController extends BaseInstallController
|
||||
{
|
||||
public function index()
|
||||
public function indexAction()
|
||||
{
|
||||
//$this->verifyStep(1);
|
||||
|
||||
@@ -40,57 +42,109 @@ class InstallController extends BaseInstallController
|
||||
return $this->render("index.html");
|
||||
}
|
||||
|
||||
public function checkPermission()
|
||||
/**
|
||||
* Integration tests
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function checkPermissionAction()
|
||||
{
|
||||
$args = array();
|
||||
var_dump('step2');
|
||||
//$this->verifyStep(2);
|
||||
|
||||
$permission = new CheckPermission();
|
||||
$checkPermission = new CheckPermission(true, $this->getTranslator());
|
||||
$args['isValid'] = $isValid = $checkPermission->exec();
|
||||
$args['validationMessages'] = $checkPermission->getValidationMessages();
|
||||
|
||||
$this->getSession()->set("step", 2);
|
||||
return $this->render("step-2.html");
|
||||
|
||||
return $this->render("step-2.html", $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Database connexion tests
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function databaseConnection()
|
||||
{
|
||||
var_dump('step 3 bis');
|
||||
}
|
||||
|
||||
/**
|
||||
* Database connexion tests
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function databaseConnectionAction()
|
||||
{
|
||||
var_dump('step 3');
|
||||
exit();
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 3);
|
||||
|
||||
return $this->render("step-3.html");
|
||||
}
|
||||
|
||||
public function databaseSelection()
|
||||
/**
|
||||
* Database selection
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function databaseSelectionAction()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 4);
|
||||
|
||||
return $this->render("step-4.html");
|
||||
}
|
||||
|
||||
public function generalInformation()
|
||||
/**
|
||||
* Set general informations
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function generalInformationAction()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 5);
|
||||
|
||||
return $this->render("step-5.html");
|
||||
}
|
||||
|
||||
public function thanks()
|
||||
/**
|
||||
* Display Thanks page
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function thanksAction()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 6);
|
||||
|
||||
return $this->render("thanks.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify each steps and redirect if one step has already been passed
|
||||
*
|
||||
* @param int $step Step number
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function verifyStep($step)
|
||||
{
|
||||
$session = $this->getSession();
|
||||
|
||||
@@ -25,15 +25,28 @@ use Thelia\Install\Exception\AlreadyInstallException;
|
||||
|
||||
/**
|
||||
* Class BaseInstall
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
abstract class BaseInstall
|
||||
{
|
||||
/** @var bool If Installation wizard is launched by CLI */
|
||||
protected $isConsoleMode = true;
|
||||
|
||||
/**
|
||||
* Verify if an installation already exists
|
||||
* Constructor
|
||||
*
|
||||
* @param bool $verifyInstall Verify if an installation already exists
|
||||
*/
|
||||
public function __construct($verifyInstall = true)
|
||||
{
|
||||
|
||||
// Check if install wizard is launched via CLI
|
||||
if (php_sapi_name() == 'cli') {
|
||||
$this->isConsoleMode = true;
|
||||
} else {
|
||||
$this->isConsoleMode = false;
|
||||
}
|
||||
/* TODO : activate this part
|
||||
if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) {
|
||||
throw new AlreadyInstallException("Thelia is already installed");
|
||||
|
||||
@@ -23,57 +23,172 @@
|
||||
|
||||
namespace Thelia\Install;
|
||||
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
|
||||
/**
|
||||
* Class CheckPermission
|
||||
*
|
||||
* Take care of integration tests (files permissions)
|
||||
*
|
||||
* @package Thelia\Install
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*/
|
||||
class CheckPermission extends BaseInstall
|
||||
{
|
||||
|
||||
const DIR_CONF = 'local/config';
|
||||
const DIR_LOG = 'log';
|
||||
const DIR_CACHE = 'cache';
|
||||
const DIR_CONF = 'local/config';
|
||||
const DIR_LOG = 'log';
|
||||
const DIR_CACHE = 'cache';
|
||||
|
||||
private $directories = array();
|
||||
private $validation = array();
|
||||
private $valid = true;
|
||||
/** @var array Directory needed to be writable */
|
||||
protected $directoriesToBeWritable = array(
|
||||
self::DIR_CONF,
|
||||
self::DIR_LOG,
|
||||
self::DIR_CACHE,
|
||||
);
|
||||
|
||||
public function __construct($verifyInstall = true)
|
||||
protected $validationMessages = array();
|
||||
|
||||
/** @var bool If permissions are OK */
|
||||
protected $isValid = true;
|
||||
|
||||
/** @var TranslatorInterface Translator Service */
|
||||
protected $translator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param bool $verifyInstall If verify install
|
||||
* @param Translator $translator Translator Service
|
||||
* necessary for install wizard
|
||||
*/
|
||||
public function __construct($verifyInstall = true, Translator $translator = null)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
|
||||
|
||||
$this->directories = array(
|
||||
self::DIR_CONF => THELIA_ROOT . 'local/config',
|
||||
self::DIR_LOG => THELIA_ROOT . 'DIR_LOG',
|
||||
self::DIR_CACHE => THELIA_ROOT . 'DIR_CACHE'
|
||||
);
|
||||
|
||||
$this->validation = array(
|
||||
self::DIR_CONF => array(
|
||||
"text" => sprintf("config directory(%s)...", $this->directories[self::DIR_CONF]),
|
||||
"status" => true
|
||||
),
|
||||
self::DIR_LOG => array(
|
||||
"text" => sprintf("DIR_CACHE directory(%s)...", $this->directories[self::DIR_LOG]),
|
||||
"status" => true
|
||||
),
|
||||
self::DIR_CACHE => array(
|
||||
"text" => sprintf("DIR_LOG directory(%s)...", $this->directories[self::DIR_CACHE]),
|
||||
"status" => true
|
||||
)
|
||||
);
|
||||
foreach ($this->directoriesToBeWritable as $directory) {
|
||||
$this->validationMessages[$directory] = array(
|
||||
'text' => '',
|
||||
'hint' => '',
|
||||
'status' => true
|
||||
);
|
||||
}
|
||||
parent::__construct($verifyInstall);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform file permission check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function exec()
|
||||
{
|
||||
foreach ($this->directories as $key => $directory) {
|
||||
if(is_writable($directory) === false) {
|
||||
$this->valid = false;
|
||||
$this->validation[$key]["status"] = false;
|
||||
foreach ($this->directoriesToBeWritable as $directory) {
|
||||
$fullDirectory = THELIA_ROOT . $directory;
|
||||
$this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, true);
|
||||
if (is_writable($fullDirectory) === false) {
|
||||
if (!$this->makeDirectoryWritable($fullDirectory)) {
|
||||
$this->isValid = false;
|
||||
$this->validationMessages[$directory]['status'] = false;
|
||||
$this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, false);
|
||||
$this->validationMessages[$directory]['hint'] = $this->getI18nHint($fullDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->isValid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get validation messages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValidationMessages()
|
||||
{
|
||||
return $this->validationMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a directory writable (recursively)
|
||||
*
|
||||
* @param string $directory path to directory
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function makeDirectoryWritable($directory)
|
||||
{
|
||||
chmod($directory, 0777);
|
||||
$iterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($directory)
|
||||
);
|
||||
foreach ($iterator as $item) {
|
||||
chmod($item, 0777);
|
||||
}
|
||||
|
||||
return (is_writable(THELIA_ROOT . $directory) === true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Translated text about the directory state
|
||||
*
|
||||
* @param string $directory Directory being checked
|
||||
* @param bool $isValid If directory permission is valid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getI18nText($directory, $isValid)
|
||||
{
|
||||
if ($this->translator !== null) {
|
||||
if ($isValid) {
|
||||
$sentence = 'Your directory <strong>%directory%</strong> is writable';
|
||||
} else {
|
||||
$sentence = 'Your directory <strong>%directory%</strong> is not writable';
|
||||
}
|
||||
|
||||
$translatedText = $this->translator->trans(
|
||||
$sentence,
|
||||
array(
|
||||
'%directory%' => $directory
|
||||
),
|
||||
'install-wizard'
|
||||
);
|
||||
} else {
|
||||
$translatedText = sprintf('Your directory %s needs to be writable', $directory);
|
||||
}
|
||||
|
||||
return $translatedText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Translated hint about the directory state
|
||||
*
|
||||
* @param string $directory Directory being checked
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getI18nHint($directory)
|
||||
{
|
||||
if ($this->translator !== null) {
|
||||
$sentence = '<span class="label label-primary">chmod 777 %directory%</span> on your server with admin rights could help';
|
||||
$translatedText = $this->translator->trans(
|
||||
$sentence,
|
||||
array(
|
||||
'%directory%' => $directory
|
||||
),
|
||||
'install-wizard'
|
||||
);
|
||||
} else {
|
||||
$translatedText = sprintf('chmod 777 %s on your server with admin rights could help', $directory);
|
||||
}
|
||||
|
||||
return $translatedText;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
- <a href="http://www.openstudio.fr/" target="_blank">{intl l='Édité par OpenStudio'}</a>
|
||||
- <a href="http://forum.thelia.net/" target="_blank">{intl l='Forum Thelia'}</a>
|
||||
- <a href="http://contrib.thelia.net/" target="_blank">{intl l='Contributions Thelia'}</a>
|
||||
<span class="pull-right">{intl l='interface par <a target="_blank" href="http://www.steaw-webdesign.com/">Steaw-Webdesign</a>'}</span>
|
||||
</p>
|
||||
|
||||
{module_include location='in_footer'}
|
||||
|
||||
@@ -24,15 +24,14 @@
|
||||
</div>
|
||||
|
||||
<div class="well">
|
||||
<p>We will check some rights to files and directories...</p>
|
||||
<p>{intl l="Checking directory permissions ..."}</p>
|
||||
<ul class="list-unstyled list-group">
|
||||
<li class="list-group-item text-success">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</li>
|
||||
<li class="list-group-item text-success">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</li>
|
||||
<li class="list-group-item text-danger">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</li>
|
||||
<li class="list-group-item text-danger">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</li>
|
||||
<li class="list-group-item text-success">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</li>
|
||||
<li class="list-group-item text-danger">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</li>
|
||||
<li class="list-group-item text-success">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</li>
|
||||
{foreach from=$validationMessages item=validationMessage}
|
||||
<li class="list-group-item {if $validationMessage.status}text-success{else}text-danger{/if}">
|
||||
{$validationMessage.text nofilter}
|
||||
{if !$validationMessage.status} - {$validationMessage.hint nofilter}{/if}
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user