Browse Source

[Global] Pouvoir mettre tout le site en maintenance #1295

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
2d90e16628
7 changed files with 73 additions and 34 deletions
  1. +0
    -2
      backend/controllers/BackendController.php
  2. +1
    -1
      backend/controllers/SiteController.php
  3. +10
    -0
      common/config/main.php
  4. +1
    -0
      common/config/params.php
  5. +6
    -1
      common/controllers/CommonController.php
  6. +18
    -0
      common/views/maintenance.php
  7. +37
    -30
      producer/controllers/ProducerBaseController.php

+ 0
- 2
backend/controllers/BackendController.php View File

{ {
$producerCurrent = $this->getProducerCurrent(); $producerCurrent = $this->getProducerCurrent();


// Contexte producteur
if($producerCurrent) { if($producerCurrent) {
$this->getLogic()->setProducerContext($producerCurrent); $this->getLogic()->setProducerContext($producerCurrent);
} }


// Pas de producteur défini
if(!$producerCurrent) { if(!$producerCurrent) {
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['dashboard/index'])); $this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['dashboard/index']));
return false; return false;

+ 1
- 1
backend/controllers/SiteController.php View File

'class' => AccessControl::class, 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'actions' => ['login', 'error'],
'actions' => ['login', 'error', 'maintenance'],
'allow' => true, 'allow' => true,
], ],
[ [

+ 10
- 0
common/config/main.php View File

Yii::$app->end(); Yii::$app->end();
} }
} }

if (Yii::$app->params['maintenanceMode']) {
if(isset($_GET['letMeIn'])) {
Yii::$app->session->set('letMeIn', (int) $_GET['letMeIn']);
}
$letMeIn = Yii::$app->session['letMeIn'];
if (!$letMeIn) {
Yii::$app->catchAll = ['site/maintenance'];
}
}
}, },
'components' => [ 'components' => [
'parameterBag' => [ 'parameterBag' => [

+ 1
- 0
common/config/params.php View File



return [ return [
'version' => '23.10.B', 'version' => '23.10.B',
'maintenanceMode' => false,
'siteName' => 'Opendistrib', 'siteName' => 'Opendistrib',
'adminEmail' => 'contact@opendistrib.net', 'adminEmail' => 'contact@opendistrib.net',
'supportEmail' => 'contact@opendistrib.net', 'supportEmail' => 'contact@opendistrib.net',

+ 6
- 1
common/controllers/CommonController.php View File

} }


return parent::beforeAction($event); return parent::beforeAction($event);
}
}

public function actionMaintenance()
{
return $this->renderFile('@common/views/maintenance.php');
}


public function getLogic(): BusinessLogic public function getLogic(): BusinessLogic
{ {

+ 18
- 0
common/views/maintenance.php View File

<!doctype html>
<title>Site en maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 40px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>

<article>
<h1>Opendistrib est en maintenance</h1>
<div>
<p>Le site sera bientôt accessible, merci pour votre patience.<br />
Si besoin, vous pouvez <a href="<?= Yii::$app->params['adminEmail']; ?>">me contacter</a>.</p>
</div>
</article>

+ 37
- 30
producer/controllers/ProducerBaseController.php View File

{ {
$producer = $this->getProducerCurrent() ; $producer = $this->getProducerCurrent() ;


$this->getLogic()->setProducerContext($producer);

$userProducer = UserProducer::find()
->where([
'id_user' => GlobalParam::getCurrentUserId(),
'id_producer' => $producer->id
])
->one() ;

/*
* Producteur hors ligne
*/
if(!$producer->active && (\Yii::$app->user->isGuest || \Yii::$app->user->identity->id_producer != $producer->id)) {
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ;
}
if(!\Yii::$app->params['maintenanceMode']) {
$this->getLogic()->setProducerContext($producer);


/*
* Producteur protègé par un code
*/
if(strlen($producer->code)) {
// Si l'utilisateur n'est pas connecté, on le redirige vers une page qui lui permet
// de se connecter ou de s'inscrire en saisissant le code du producteur
if(\Yii::$app->user->isGuest) {
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
$userProducer = UserProducer::find()
->where([
'id_user' => GlobalParam::getCurrentUserId(),
'id_producer' => $producer->id
])
->one() ;

/*
* Producteur hors ligne
*/
if(!$producer->active && (\Yii::$app->user->isGuest || \Yii::$app->user->identity->id_producer != $producer->id)) {
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ;
} }
// si l'utilisateur est connecté et qu'il n'a pas encore saisi de code
else {
if(!$userProducer || ($userProducer && !$userProducer->active)) {
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ;

/*
* Producteur protègé par un code
*/
if(strlen($producer->code)) {

// Si l'utilisateur n'est pas connecté, on le redirige vers une page qui lui permet
// de se connecter ou de s'inscrire en saisissant le code du producteur
if(\Yii::$app->user->isGuest) {
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $producer->id])) ;
}
// si l'utilisateur est connecté et qu'il n'a pas encore saisi de code
else {
if(!$userProducer || ($userProducer && !$userProducer->active)) {
$this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ;
}
} }
} }
} }
/** /**
* Retourne le producteur courant. * Retourne le producteur courant.
*/ */
public function getProducerCurrent() : Producer
public function getProducerCurrent() : ?Producer
{ {
if($this->producer) { if($this->producer) {
return $this->producer ; return $this->producer ;
return $this->producer ; return $this->producer ;
} }
else { else {
throw new \yii\web\HttpException(404, 'Producteur introuvable ('.$slug.')');
if($this->action->id != 'maintenance') {
throw new \yii\web\HttpException(404, 'Producteur introuvable ('.$slug.')');
}
else {
return null;
}
} }
} }
} }

Loading…
Cancel
Save