-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathutils.php
More file actions
55 lines (44 loc) · 1.34 KB
/
utils.php
File metadata and controls
55 lines (44 loc) · 1.34 KB
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
<?php
namespace EE\Cron\Utils;
use EE;
use EE\Model\Cron;
use EE_DOCKER;
use EE\Utils as EE_Utils;
use Mustache_Engine;
/**
* Generates cron config from DB
*/
function update_cron_config() {
$config = generate_cron_config();
file_put_contents( EE_ROOT_DIR . '/services/cron/config.ini', $config );
EE_DOCKER::restart_container( EE_CRON_SCHEDULER );
}
/**
* Generates and returns cron config from DB
*/
function generate_cron_config() {
$config_template = file_get_contents( __DIR__ . '/../../templates/config.ini.mustache' );
$crons = Cron::all();
foreach ( $crons as &$cron ) {
$job_type = 'host' === $cron->site_url ? 'job-local' : 'job-exec';
$id = $cron->site_url . '-' . preg_replace( '/[^a-zA-Z0-9\@]/', '-', $cron->command ) . '-' . EE_Utils\random_password( 5 );
$id = preg_replace( '/--+/', '-', $id );
$cron->job_type = $job_type;
$cron->id = $id;
if ( 'host' !== $cron->site_url ) {
$cron->container = site_php_container( $cron->site_url );
}
}
$me = new Mustache_Engine();
return $me->render( $config_template, $crons );
}
/**
* Returns php container name of a site.
*
* @param string $site Name of the site whose container name is needed.
*
* @return string Container name.
*/
function site_php_container( $site ) {
return str_replace( '.', '', $site ) . '_php_1';
}