This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaircloak-deploy-plugin.php
86 lines (75 loc) · 2.2 KB
/
aircloak-deploy-plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
Plugin Name: Aircloak deployment
Description: Provides a one-click ability to deploy our website
Version: 0.1.0
Author: Sebastian Probst Eide
Text Domain: aircloak-wordpress-deploy
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action('admin_menu', 'ac_deploy_add_menu');
function ac_deploy_add_menu() {
add_management_page(
'Deploy stage website to production',
'Deploy to prod',
'manage_options',
'acdeploy',
'ac_deployment_page'
);
}
function render_currently_deploying() {
?>
<META HTTP-EQUIV="REFRESH" CONTENT="1">
<p>
<strong>Notice:</strong> the site is currently being deployed.
</p>
<p>
This page automatically refreshes every second and will go back to the default button once deployed.
</p>
<?php
}
function is_deploying() {
return file_exists('/tmp/aircloak-website-currently-deploying');
}
// mt_tools_page() displays the page content for the Test Tools submenu
function ac_deployment_page() {
//must check that the user has the required capability
if (!current_user_can('manage_options'))
{
wp_die( __('You do not have sufficient permissions to access this page.') );
}
?>
<h1>Aircloak stage to production deployment</h1>
<?php
// variables for the field and option names
$hidden_field_name = 'ac_hidden_field';
if ( is_deploying() ) {
render_currently_deploying();
} else {
// See if the user submitted the "deploy" button command
if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' ) {
exec("/usr/local/bin/aircloak-website-release.sh >/tmp/ac-deploy-log.txt 2>/tmp/ac-deploy-log.txt &");
render_currently_deploying();
} else {
?>
<div class="wrap">
<form name="deploy_form" method="post" action="">
<input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y">
<p class="submit">
<input type="submit" name="Deploy website" class="button-primary" value="Deploy website to production" />
</p>
</form>
</div>
<?php
if ( file_exists('/tmp/ac-deploy-log.txt') ) {
echo "<h2>Previous deployment log</h2>";
echo "<pre>";
readfile('/tmp/ac-deploy-log.txt');
echo "</pre>";
}
}
}
}