function main in Acquia Cloud Site Factory Connector 8.2
Same name and namespace in other branches
The entry point into the script.
Determines whether there are theme files, and request them from the Site Factory if needed.
Parameters
string $argv: The command line arguments.
int $argc: The number of command line arguments.
File
- acsf_init/
lib/ cloud_hooks/ common/ pre-web-activate/ 000-acquia-deployment.php, line 49 - This script is responsible for deploying theme files on each webnode.
Code
function main($argv, $argc) {
if ($argc < 3) {
printf("Must provide the sitegroup name and environment name.\n");
exit(1);
}
$site = $argv[1];
$env = $argv[2];
$registry_path = get_registry_file($site, $env);
if (!file_exists($registry_path)) {
printf("This doesn't look like an ACSF environment. Will not update ACSF themes.\n");
exit(0);
}
$verbose = FALSE;
if (in_array('-v', $argv) || in_array('--verbose', $argv)) {
$verbose = TRUE;
}
$force = FALSE;
if (in_array('-f', $argv) || in_array('--force', $argv)) {
$force = TRUE;
}
$deployed = has_theme_files($site, $env);
if ($force || !$deployed) {
$webnode = gethostname();
if ($verbose) {
if (!$deployed) {
printf("Theme files have not been deployed on %s for %s.%s\n", $webnode, $site, $env);
}
else {
printf("Forcing theme deployment on %s for %s.%s\n", $webnode, $site, $env);
}
}
// Assume we will fail until proven otherwise.
$success = FALSE;
// Send Site Factory request.
$attempts = $max_attempts = 6;
do {
$response = request_theme_files($site, $env, $webnode);
if ($verbose) {
printf("Sent request to the Site Factory for themes: %s\n", print_r($response, TRUE));
}
// Poll waiting for theme deployment.
if ($response->code == 200) {
$task_id = $response->body['task_id'];
if ($task_id == 'NA') {
printf("VCS theming is not configured for %s.%s\n", $site, $env);
exit;
}
// Wait here until the themes are deployed.
do {
sleep(10);
$task_info = get_wip_task_status($site, $env, $task_id);
$task = $task_info->body['wip_task'];
if ($verbose) {
printf("Wip task status: %s\n", print_r($task, TRUE));
}
} while ($task['status'] < WIP_STATUS_COMPLETED);
// Note: STATUS_WARNING is 144, which has the 16 (STATUS_COMPLETED) bit
// set, so checking against 16 will be true for both completed, and
// warning.
if ($task['status'] & WIP_STATUS_COMPLETED) {
$success = TRUE;
break;
}
}
sleep(10 * ($max_attempts - $attempts));
} while ($attempts-- > 0);
if (!$success) {
// Failed to deploy the theme files.
printf("Failed to deploy theme files to %s for %s.%s\n", $webnode, $site, $env);
exit(1);
}
}
}