Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #155 from devuri/feat-handles-maintenance
Browse files Browse the repository at this point in the history
Feat handles maintenance
  • Loading branch information
devuri authored Sep 8, 2023
2 parents 09561f2 + 982b319 commit 3b494c3
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 14 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"php": "^7.4 || ^8.0",
"aws/aws-sdk-php": "^3.275",
"defuse/php-encryption": "^2.4",
"devuri/cpt-meta-box": "^0.4",
"devuri/dot-access": "^0.2.2",
"devuri/encryption": "^0.1",
"devuri/secure-password": "^0.1",
Expand Down
55 changes: 53 additions & 2 deletions docs/code/classes/Urisoft-App-Console-ConfigCommand.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ <h3 id="toc">
<span>
&nbsp;: array&lt;string|int, string&gt; </span>
</dt>
<dd></dd>

<dt class="phpdocumentor-table-of-contents__entry -method -protected">
<a href="classes/Urisoft-App-Console-ConfigCommand.html#method_set_maintenance_mode">set_maintenance_mode()</a>
<span>
&nbsp;: void </span>
</dt>
<dd></dd>

<dt class="phpdocumentor-table-of-contents__entry -method -private">
Expand Down Expand Up @@ -1048,7 +1055,7 @@ <h4 class="phpdocumentor-element__name" id="method_create_htpasswd_file">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/App/Console/ConfigCommand.php"><a href="files/src-app-console-configcommand.html"><abbr title="src/App/Console/ConfigCommand.php">ConfigCommand.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">113</span>
<span class="phpdocumentor-element-found-in__line">125</span>

</aside>

Expand Down Expand Up @@ -1539,6 +1546,50 @@ <h5 class="phpdocumentor-return-value__heading">Return values</h5>
&mdash;


</article>
<article
class="phpdocumentor-element
-method
-protected
"
>
<h4 class="phpdocumentor-element__name" id="method_set_maintenance_mode">
set_maintenance_mode()
<a href="classes/Urisoft-App-Console-ConfigCommand.html#method_set_maintenance_mode" class="headerlink"><i class="fas fa-link"></i></a>
</h4>
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/App/Console/ConfigCommand.php"><a href="files/src-app-console-configcommand.html"><abbr title="src/App/Console/ConfigCommand.php">ConfigCommand.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">147</span>

</aside>


<code class="phpdocumentor-code phpdocumentor-signature ">
<span class="phpdocumentor-signature__visibility">protected</span>
<span class="phpdocumentor-signature__name">set_maintenance_mode</span><span>(</span><span class="phpdocumentor-signature__argument"><span class="phpdocumentor-signature__argument__return-type">mixed&nbsp;</span><span class="phpdocumentor-signature__argument__name">$_task</span></span><span>)</span><span> : </span><span class="phpdocumentor-signature__response_type">void</span></code>

<section class="phpdocumentor-description"></section>

<h5 class="phpdocumentor-argument-list__heading">Parameters</h5>
<dl class="phpdocumentor-argument-list">
<dt class="phpdocumentor-argument-list__entry">
<span class="phpdocumentor-signature__argument__name">$_task</span>
: <span class="phpdocumentor-signature__argument__return-type">mixed</span>
</dt>
<dd class="phpdocumentor-argument-list__definition">
<section class="phpdocumentor-description"></section>

</dd>
</dl>



<h5 class="phpdocumentor-return-value__heading">Return values</h5>
<span class="phpdocumentor-signature__response_type">void</span>
&mdash;


</article>
<article
class="phpdocumentor-element
Expand Down Expand Up @@ -1653,7 +1704,7 @@ <h4 class="phpdocumentor-element__name" id="method_load_dotenv">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/App/Console/ConfigCommand.php"><a href="files/src-app-console-configcommand.html"><abbr title="src/App/Console/ConfigCommand.php">ConfigCommand.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">142</span>
<span class="phpdocumentor-element-found-in__line">168</span>

</aside>

Expand Down
10 changes: 5 additions & 5 deletions docs/code/classes/Urisoft-App-Core-AutoLogin.html
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ <h4 class="phpdocumentor-element__name" id="method___construct">

<code class="phpdocumentor-code phpdocumentor-signature ">
<span class="phpdocumentor-signature__visibility">public</span>
<span class="phpdocumentor-signature__name">__construct</span><span>(</span><span class="phpdocumentor-signature__argument"><span class="phpdocumentor-signature__argument__return-type">string&nbsp;</span><span class="phpdocumentor-signature__argument__name">$secret_key</span></span><span class="phpdocumentor-signature__argument"><span>, </span><span class="phpdocumentor-signature__argument__return-type">string&nbsp;</span><span class="phpdocumentor-signature__argument__name">$environment_type</span></span><span>)</span><span> : </span><span class="phpdocumentor-signature__response_type">void</span></code>
<span class="phpdocumentor-signature__name">__construct</span><span>(</span><span class="phpdocumentor-signature__argument"><span>[</span><span class="phpdocumentor-signature__argument__return-type">string|null&nbsp;</span><span class="phpdocumentor-signature__argument__name">$secret_key</span><span> = </span><span class="phpdocumentor-signature__argument__default-value">null</span><span> ]</span></span><span class="phpdocumentor-signature__argument"><span>[</span><span>, </span><span class="phpdocumentor-signature__argument__return-type">string|null&nbsp;</span><span class="phpdocumentor-signature__argument__name">$environment_type</span><span> = </span><span class="phpdocumentor-signature__argument__default-value">null</span><span> ]</span></span><span>)</span><span> : </span><span class="phpdocumentor-signature__response_type">void</span></code>

<section class="phpdocumentor-description"><p>Initializes the AutoLogin class with necessary properties and settings.</p>
<p>The constructor sets up the class properties required for the auto-login functionality.
Expand All @@ -435,16 +435,16 @@ <h5 class="phpdocumentor-argument-list__heading">Parameters</h5>
<dl class="phpdocumentor-argument-list">
<dt class="phpdocumentor-argument-list__entry">
<span class="phpdocumentor-signature__argument__name">$secret_key</span>
: <span class="phpdocumentor-signature__argument__return-type">string</span>
</dt>
: <span class="phpdocumentor-signature__argument__return-type">string|null</span>
= <span class="phpdocumentor-signature__argument__default-value">null</span> </dt>
<dd class="phpdocumentor-argument-list__definition">
<section class="phpdocumentor-description"></section>

</dd>
<dt class="phpdocumentor-argument-list__entry">
<span class="phpdocumentor-signature__argument__name">$environment_type</span>
: <span class="phpdocumentor-signature__argument__return-type">string</span>
</dt>
: <span class="phpdocumentor-signature__argument__return-type">string|null</span>
= <span class="phpdocumentor-signature__argument__default-value">null</span> </dt>
<dd class="phpdocumentor-argument-list__definition">
<section class="phpdocumentor-description"></section>

Expand Down
6 changes: 3 additions & 3 deletions docs/code/classes/Urisoft-App-Core-Plugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ <h4 class="phpdocumentor-element__name" id="method_init">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/App/Core/Plugin.php"><a href="files/src-app-core-plugin.html"><abbr title="src/App/Core/Plugin.php">Plugin.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">130</span>
<span class="phpdocumentor-element-found-in__line">136</span>

</aside>

Expand Down Expand Up @@ -252,7 +252,7 @@ <h4 class="phpdocumentor-element__name" id="method_extract_domain">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/App/Core/Plugin.php"><a href="files/src-app-core-plugin.html"><abbr title="src/App/Core/Plugin.php">Plugin.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">160</span>
<span class="phpdocumentor-element-found-in__line">166</span>

</aside>

Expand Down Expand Up @@ -299,7 +299,7 @@ <h4 class="phpdocumentor-element__name" id="method_security_headers">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/App/Core/Plugin.php"><a href="files/src-app-core-plugin.html"><abbr title="src/App/Core/Plugin.php">Plugin.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">135</span>
<span class="phpdocumentor-element-found-in__line">141</span>

</aside>

Expand Down
5 changes: 5 additions & 0 deletions docs/code/js/searchIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ Search.appendIndex(
"name": "create_htpasswd_file",
"summary": "",
"url": "classes/Urisoft-App-Console-ConfigCommand.html#method_create_htpasswd_file"
}, {
"fqsen": "\\Urisoft\\App\\Console\\ConfigCommand\u003A\u003Aset_maintenance_mode\u0028\u0029",
"name": "set_maintenance_mode",
"summary": "",
"url": "classes/Urisoft-App-Console-ConfigCommand.html#method_set_maintenance_mode"
}, {
"fqsen": "\\Urisoft\\App\\Console\\ConfigCommand\u003A\u003Aload_dotenv\u0028\u0029",
"name": "load_dotenv",
Expand Down
26 changes: 26 additions & 0 deletions src/App/Console/ConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ protected function execute( InputInterface $input, OutputInterface $output ): in

$config_task = $input->getArgument( '_task' );

// handles maintenance.
if ( 'up' === $config_task ) {
$this->set_maintenance_mode( 'up' );

return Command::SUCCESS;
}
if ( 'down' === $config_task ) {
$this->set_maintenance_mode( 'down' );

return Command::SUCCESS;
}

if ( false === $config_task ) {
$output->writeln( "<info>Config Setup for:$this->root_dir_path</info>" );

Expand Down Expand Up @@ -132,6 +144,20 @@ protected function create_htpasswd_file( string $config_task, OutputInterface $o
}
}

protected function set_maintenance_mode( $_task ): void
{
if ( 'up' === $_task ) {
if ( $this->filesystem->exists( $this->root_dir_path . '/public/.maintenance' ) ) {
$this->filesystem->remove( $this->root_dir_path . '/public/.maintenance' );
}

return;
}
if ( 'down' === $_task ) {
$this->filesystem->dumpFile( $this->root_dir_path . '/public/.maintenance', 'Maintenance mode' );
}
}

/**
* Load the $_ENV.
*
Expand Down
2 changes: 1 addition & 1 deletion src/App/Core/AutoLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AutoLogin
*
* @return void This method does not return any value.
*/
public function __construct( string $secret_key, string $environment_type )
public function __construct( ?string $secret_key = null, ?string $environment_type = null )
{
$this->secret_key = $secret_key;
$this->environment_type = $environment_type;
Expand Down
12 changes: 9 additions & 3 deletions src/App/Core/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function __construct()
BasicAuth::init();

// allows auto login.
AutoLogin::init( env( 'WPENV_AUTO_LOGIN_SECRET_KEY' ), env( 'WP_ENVIRONMENT_TYPE' ) );
if ( env( 'WPENV_AUTO_LOGIN_SECRET_KEY' ) ) {
AutoLogin::init( env( 'WPENV_AUTO_LOGIN_SECRET_KEY' ), env( 'WP_ENVIRONMENT_TYPE' ) );
}

add_action(
'send_headers',
Expand Down Expand Up @@ -68,7 +70,11 @@ function ( $admin_bar ): void {
return;
}

$env_label = strtoupper( HTTP_ENV_CONFIG );
if ( \defined( 'HTTP_ENV_CONFIG' ) && HTTP_ENV_CONFIG ) {
$env_label = strtoupper( HTTP_ENV_CONFIG );
} else {
$env_label = null;
}

$admin_bar->add_menu(
[
Expand All @@ -77,7 +83,7 @@ function ( $admin_bar ): void {
'href' => '#',
'meta' => [
'title' => __( 'Environment: ' ) . $env_label,
'class' => 'qm-warning',
'class' => 'wpc-warning',
],
]
);
Expand Down

0 comments on commit 3b494c3

Please sign in to comment.