Skip to content

Commit 2675b32

Browse files
authored
Fix PHP 8.0 Support (#706)
- Rename `devshop/omposer-common` to `devshop/git-traits` because that is all it did. - Fix all the warnings. - Untangle composer dependencies. - Update test project. - Add 8.0 to the test matrix.
1 parent 4bfb2f2 commit 2675b32

File tree

20 files changed

+366
-278
lines changed

20 files changed

+366
-278
lines changed

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
],
2323
"require": {
2424
"cpliakas/git-wrapper": "~1.0",
25-
"knplabs/github-api": "^3.8",
26-
"php-http/guzzle7-adapter": "^1.1",
25+
"guzzlehttp/guzzle": "^6",
26+
"knplabs/github-api": "^3.0||^1.0",
2727
"sensiolabs/ansi-to-html": "^1.1",
2828
"symfony/process": "^3.4",
2929
"symfony/yaml": "^3.4",
@@ -32,7 +32,10 @@
3232
"minimum-stability": "dev",
3333
"prefer-stable": true,
3434
"config": {
35-
"sort-packages": true
35+
"sort-packages": true,
36+
"platform": {
37+
"php": "7.4.0"
38+
}
3639
},
3740
"extra": {
3841
"installer-paths": {

modules/devshop/aegir_download/aegir_download.module

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function hosting_task_download_form() {
6161
* Defines the list of tasks that appear under the gear icon.
6262
*/
6363
function aegir_download_devshop_environment_menu($environment) {
64-
64+
$items = [];
6565
if ($environment->site && $environment->site_status == HOSTING_SITE_ENABLED) {
6666
$items[] = 'download';
6767
}

modules/devshop/aegir_update/aegir_update.module

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function aegir_update_post_hosting_update_drupal_task($task, $data) {
7676
* Defines the list of tasks that appear under the gear icon.
7777
*/
7878
function aegir_update_devshop_environment_menu($environment) {
79-
79+
$items = [];
8080
if ($environment->site && $environment->site_status == HOSTING_SITE_ENABLED) {
8181
$items[] = 'update_drupal';
8282
}

modules/devshop/devshop_github/devshop_github.module

Lines changed: 96 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ function devshop_github_form_devshop_project_create_step_environments_alter(&$fo
768768
// Load the PRs.
769769
try {
770770
$prs = devshop_github_client()->pullRequests()->all($project->github_owner, $project->github_repo);
771-
771+
$settings_link = '';
772772
$environment_forms = array();
773773
if (!empty($project->settings->github['pull_request_environments'])) {
774774

@@ -1569,131 +1569,132 @@ function devshop_github_webhook($project_node) {
15691569
$environment = $project->environments[$environment_name];
15701570

15711571
// Environment might have been deleted.
1572-
if (empty($environment)) {
1572+
if (!empty($environment)) {
15731573
$message .= "Environment $environment_name not found in project $project->name.";
1574-
continue;
15751574
}
1575+
else {
15761576

1577-
$message .= "About to set deployment status for repo $owner/$repo using environment $environment_name \n";
1578-
$message .= "Environment: " . print_r($environment, 1);
1579-
1580-
try {
1581-
$token = variable_get('devshop_github_token', '');
1582-
$client = new \Github\Client();
1583-
$client->authenticate($token, \Github\AuthMethod::ACCESS_TOKEN);
1584-
1585-
$sha = $data->pull_request->head->sha;
1586-
1587-
$params = new stdClass();
1588-
$params->ref = $sha;
1589-
$params->environment = $environment->url;
1590-
$params->required_contexts = array();
1591-
$post_url = "/repos/$owner/$repo/deployments";
1592-
$deployment = json_decode($client->getHttpClient()->post($post_url, json_encode($params))->getBody(TRUE));
1577+
$message .= "About to set deployment status for repo $owner/$repo using environment $environment_name \n";
1578+
$message .= "Environment: " . print_r($environment, 1);
15931579

1594-
// Save deployment to pull request data for later access.
1595-
$data->pull_request->deployment = $deployment;
1580+
try {
1581+
$token = variable_get('devshop_github_token', '');
1582+
$client = new \Github\Client();
1583+
$client->authenticate($token, \Github\AuthMethod::ACCESS_TOKEN);
15961584

1597-
$message .= " Deployment Created! \n";
1585+
$sha = $data->pull_request->head->sha;
15981586

1599-
// Create deployment status
1600-
$deployment_id = $deployment->id;
1587+
$params = new stdClass();
1588+
$params->ref = $sha;
1589+
$params->environment = $environment->url;
1590+
$params->required_contexts = array();
1591+
$post_url = "/repos/$owner/$repo/deployments";
1592+
$deployment = json_decode($client->getHttpClient()->post($post_url, json_encode($params))->getBody(TRUE));
16011593

1602-
$params = new stdClass();
1603-
$params->state = 'pending';
1604-
$params->target_url = $environment->url;
1605-
$params->description = t('Code is being deployed. Please stand by.');
1594+
// Save deployment to pull request data for later access.
1595+
$data->pull_request->deployment = $deployment;
16061596

1607-
$post_url = "/repos/$owner/$repo/deployments/{$deployment_id}/statuses";
1608-
$message .= "Attempting to create deployment status: $post_url \n";
1597+
$message .= " Deployment Created! \n";
16091598

1610-
$deployment_status = $client->getHttpClient()->post($post_url, json_encode($params));
1599+
// Create deployment status
1600+
$deployment_id = $deployment->id;
16111601

1612-
$message .= " Deployment Status Created! \n";
1602+
$params = new stdClass();
1603+
$params->state = 'pending';
1604+
$params->target_url = $environment->url;
1605+
$params->description = t('Code is being deployed. Please stand by.');
16131606

1614-
// Set a commit status for this REF for devshop/deploy context
1615-
$sha = $data->pull_request->head->sha;
1607+
$post_url = "/repos/$owner/$repo/deployments/{$deployment_id}/statuses";
1608+
$message .= "Attempting to create deployment status: $post_url \n";
16161609

1617-
$params = new stdClass();
1618-
$params->state = 'pending';
1619-
$params->target_url = url("node/$project->nid", array('absolute' => TRUE));
1620-
$params->description = t('DevShop: Deploy');
1621-
$params->context = "devshop/{$project->name}/deploy";
1610+
$deployment_status = $client->getHttpClient()->post($post_url, json_encode($params));
16221611

1623-
// Post status to github
1624-
$status = $client->getHttpClient()->post("/repos/$owner/$repo/statuses/$sha", json_encode($params));
1612+
$message .= " Deployment Status Created! \n";
16251613

1626-
$message .= " Commit Status Created! \n";
1614+
// Set a commit status for this REF for devshop/deploy context
1615+
$sha = $data->pull_request->head->sha;
16271616

1628-
// If environment is configured to run tests, add another status.
1629-
if (!empty($environment->settings->deploy['test'])) {
16301617
$params = new stdClass();
16311618
$params->state = 'pending';
1632-
1633-
// @TODO: Add the link to the last "test" task here instead of the project.
16341619
$params->target_url = url("node/$project->nid", array('absolute' => TRUE));
1635-
$params->description = t('DevShop: Run Tests');
1636-
$params->context = "devshop/{$project->name}/tests";
1620+
$params->description = t('DevShop: Deploy');
1621+
$params->context = "devshop/{$project->name}/deploy";
16371622

16381623
// Post status to github
16391624
$status = $client->getHttpClient()->post("/repos/$owner/$repo/statuses/$sha", json_encode($params));
16401625

1641-
$message .= " Commit Status Created for test runs! \n";
1626+
$message .= " Commit Status Created! \n";
1627+
1628+
// If environment is configured to run tests, add another status.
1629+
if (!empty($environment->settings->deploy['test'])) {
1630+
$params = new stdClass();
1631+
$params->state = 'pending';
1632+
1633+
// @TODO: Add the link to the last "test" task here instead of the project.
1634+
$params->target_url = url("node/$project->nid", array('absolute' => TRUE));
1635+
$params->description = t('DevShop: Run Tests');
1636+
$params->context = "devshop/{$project->name}/tests";
1637+
1638+
// Post status to github
1639+
$status = $client->getHttpClient()->post("/repos/$owner/$repo/statuses/$sha", json_encode($params));
1640+
1641+
$message .= " Commit Status Created for test runs! \n";
1642+
}
1643+
1644+
} catch (Github\Exception\RuntimeException $e) {
1645+
$log = 'GitHub API Error during PR Syncronize: ' . $e->getMessage() . $e->getCode();
1646+
watchdog('devshop_github', $log);
1647+
1648+
if ($e->getCode() == '409') {
1649+
$log .= "\n Out of date! alert the developer!";
1650+
1651+
// Send a failed commit status to alert to developer
1652+
$params = new stdClass();
1653+
$params->state = 'failure';
1654+
$params->target_url = $project->git_repo_url;
1655+
$params->description = t('Branch is out of date! Merge from default branch.');
1656+
$params->context = "devshop/{$project->name}/merge";
1657+
1658+
// Post status to github
1659+
$status = $client->getHttpClient()->post("/repos/$owner/$repo/statuses/$sha", json_encode($params));
1660+
}
1661+
else {
1662+
http_response_code(500);
1663+
}
1664+
$message .= $log . "\n";
16421665
}
16431666

1644-
} catch (Github\Exception\RuntimeException $e) {
1645-
$log = 'GitHub API Error during PR Syncronize: ' . $e->getMessage() . $e->getCode();
1646-
watchdog('devshop_github', $log);
16471667

1648-
if ($e->getCode() == '409') {
1649-
$log .= "\n Out of date! alert the developer!";
1668+
// Update the PR record
1669+
$info = new stdClass();
1670+
$info->site_nid = $environment->site;
1671+
$info->id = $data->pull_request->id;
1672+
$info->number = $data->pull_request->number;
1673+
$info->pull_request_object = serialize($data->pull_request);
16501674

1651-
// Send a failed commit status to alert to developer
1652-
$params = new stdClass();
1653-
$params->state = 'failure';
1654-
$params->target_url = $project->git_repo_url;
1655-
$params->description = t('Branch is out of date! Merge from default branch.');
1656-
$params->context = "devshop/{$project->name}/merge";
1675+
// Save environment record.
1676+
$results = db_select('hosting_devshop_github_pull_requests', 'pr')
1677+
->condition('id', $data->pull_request->id)
1678+
->fields('pr', array('id'))
1679+
->execute()
1680+
->fetchAssoc();
16571681

1658-
// Post status to github
1659-
$status = $client->getHttpClient()->post("/repos/$owner/$repo/statuses/$sha", json_encode($params));
1682+
// If there are results, save $update param for drupal_write_record().
1683+
if (empty($results)) {
1684+
$update = array();
16601685
}
16611686
else {
1662-
http_response_code(500);
1687+
$update = array('id');
16631688
}
1664-
$message .= $log . "\n";
1665-
}
1666-
1667-
1668-
// Update the PR record
1669-
$info = new stdClass();
1670-
$info->site_nid = $environment->site;
1671-
$info->id = $data->pull_request->id;
1672-
$info->number = $data->pull_request->number;
1673-
$info->pull_request_object = serialize($data->pull_request);
1674-
1675-
// Save environment record.
1676-
$results = db_select('hosting_devshop_github_pull_requests', 'pr')
1677-
->condition('id', $data->pull_request->id)
1678-
->fields('pr', array('id'))
1679-
->execute()
1680-
->fetchAssoc();
1681-
1682-
// If there are results, save $update param for drupal_write_record().
1683-
if (empty($results)) {
1684-
$update = array();
1685-
}
1686-
else {
1687-
$update = array('id');
1688-
}
16891689

1690-
// Save environment record.
1691-
try {
1692-
drupal_write_record('hosting_devshop_github_pull_requests', $info, $update);
1693-
$message .= ' ' . t('Pull Request info saved to DevShop.');
1694-
}
1695-
catch (\PDOException $e) {
1696-
$message .= 'Saving PR record failed: ' . $e->getMessage();
1690+
// Save environment record.
1691+
try {
1692+
drupal_write_record('hosting_devshop_github_pull_requests', $info, $update);
1693+
$message .= ' ' . t('Pull Request info saved to DevShop.');
1694+
}
1695+
catch (\PDOException $e) {
1696+
$message .= 'Saving PR record failed: ' . $e->getMessage();
1697+
}
16971698
}
16981699
}
16991700
// When PR is closed, delete environment.

modules/devshop/devshop_projects/devshop_projects.drush.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function drush_devshop_projects_pre_hosting_task()
3636
$task =& drush_get_context('HOSTING_TASK');
3737

3838
// For all tasks
39-
if ($task->ref->type == 'site' || $task->ref->type == 'platform' || $task->ref->type == 'project') {
39+
if (isset($task->ref->project) && ($task->ref->type == 'site' || $task->ref->type == 'platform' || $task->ref->type == 'project')) {
4040
$drush_aliases = new Provision_Config_ProjectAliases($task->ref->project->name, $task->ref->project);
4141
}
4242

modules/devshop/devshop_projects/devshop_projects.module

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,10 @@ function devshop_projects_menu_alter(&$items) {
574574
'access callback' => TRUE,
575575
);
576576

577-
$items['admin/devshop/cloud'] = $items['admin/hosting/cloud'];
578-
$items['admin/devshop/cloud']['weight'] = 10;
579-
577+
if (isset($items['admin/hosting/cloud'])) {
578+
$items['admin/devshop/cloud'] = $items['admin/hosting/cloud'];
579+
$items['admin/devshop/cloud']['weight'] = 10;
580+
}
580581
}
581582

582583
/**

modules/devshop/devshop_projects/inc/create/create.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ function devshop_projects_add_status($type = 'platform') {
264264
$nids = array();
265265

266266
// When checking project...
267-
if ($type == 'project') {
267+
if ($type == 'project' && isset($project_node->nid)) {
268268
$tasks = hosting_get_tasks('rid', $project_node->nid);
269269
$last_task = array_shift($tasks);
270270
$status = _hosting_parse_error_code($last_task->task_status);

modules/devshop/devshop_projects/inc/create/step-3.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ function devshop_project_create_step_environments_submit(&$form, &$form_state) {
273273
*/
274274
function devshop_project_environment_create_form_element($project, $environment) {
275275

276-
$name = $environment->name;
276+
$name = isset($environment->name) ? $environment->name : '';
277277

278278
$element = array(
279279
'#tree' => TRUE,

modules/devshop/devshop_projects/inc/forms.inc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ HTML;
805805
function devshop_projects_form_site_node_form_alter(&$form, &$form_state, $form_id) {
806806

807807
$node = $form['#node'];
808+
$environment = NULL;
808809

809810
$form['environment'] = array(
810811
'#weight' => -9,
@@ -1113,7 +1114,7 @@ function devshop_projects_create_environment_form(&$form, &$form_state, $form_id
11131114
),
11141115
)) . '</small>';
11151116
$git_ref = $environment->git_ref;
1116-
$icon = $environment->git_ref_type == 'tag'? 'tag': 'code-fork';
1117+
$icon = isset($environment->git_ref_type) && $environment->git_ref_type == 'tag'? 'tag': 'code-fork';
11171118
$environment_options[$environment->system_alias] = "<span>{$environment->name}</span> <small class='git-ref text-muted'><i class='fa fa-$icon'></i> $git_ref</small> <small>$link</small>";
11181119
}
11191120

@@ -1288,6 +1289,7 @@ function devshop_projects_create_environment_form(&$form, &$form_state, $form_id
12881289
$form['platform']['#access'] = FALSE;
12891290
$form['profile']['#access'] = FALSE;
12901291
$form['git']['#access'] = FALSE;
1292+
12911293
}
12921294

12931295
/**
@@ -1317,7 +1319,7 @@ function devshop_projects_create_environment_form_validate_name($element, &$form
13171319
form_set_value($form['title'], devshop_environment_url($project, $element['#value']), $form_state);
13181320

13191321
// Attach a new platform node.
1320-
$platform_node = devshop_prepare_platform_node($project, $element['#value'], $form_state['values']['git_ref'], $form_state['values']['web_server'], $form_state['values']['git']['repo_url']);
1322+
$platform_node = devshop_prepare_platform_node($project, $element['#value'], $form_state['values']['git_ref'], $form_state['values']['web_server']);
13211323

13221324
// Set value in form_state.
13231325
form_set_value($form['platform_node'], $platform_node, $form_state);
@@ -1366,7 +1368,7 @@ function devshop_prepare_platform_node($project, $environment_name, $git_ref, $w
13661368
}
13671369

13681370
$platform_node->git_reference = $git_ref;
1369-
$platform_node->git_reset = $project->git_reset? $project->git_reset: 0;
1371+
$platform_node->git_reset = isset($project->git_reset) ? $project->git_reset: 0;
13701372

13711373

13721374
// Enable git pull queue for this platform if chosen.
@@ -1445,7 +1447,7 @@ function devshop_projects_create_environment_form_validate_import($element, &$fo
14451447
if ($form_state['values']['install_method']['method'] == 'import' && empty($element['#value'])) {
14461448
form_set_error('install_method][import', t('If using the "Import Database" Install Method, you must enter a MySQL connection URL or absolute path to an SQL file.'));
14471449
}
1448-
elseif ($url_components['scheme'] == 'mysql') {
1450+
elseif (isset($url_components['scheme']) && $url_components['scheme'] == 'mysql') {
14491451
$database = array(
14501452
'database' => ltrim($url_components['path'], '/'),
14511453
'username' => $url_components['user'],
@@ -1533,7 +1535,7 @@ function devshop_environment_add_form_profile_options($project) {
15331535
function devshop_environment_deploy_hooks_form($project, $environment = NULL, $task_type = NULL) {
15341536

15351537
// If environment not specified, just grab one.
1536-
if (!$environment) {
1538+
if (!$environment && isset($project->environments)) {
15371539
$environment = current($project->environments);
15381540
$is_environment_form = FALSE;
15391541
}
@@ -1626,8 +1628,8 @@ function devshop_environment_deploy_hooks_form($project, $environment = NULL, $t
16261628
// Disable deploy hooks on environment form, deploy task form ,and sync task form.
16271629
if (
16281630
// Environment form
1629-
($is_environment_form && !$project->settings->deploy['allow_environment_deploy_config']) ||
1630-
($task_type == 'deploy' && !$project->settings->deploy['allow_environment_deploy_hooks_override'])
1631+
($is_environment_form && isset($project->settings) && !$project->settings->deploy['allow_environment_deploy_config']) ||
1632+
($task_type == 'deploy' && isset($project->settings) && !$project->settings->deploy['allow_environment_deploy_hooks_override'])
16311633
) {
16321634

16331635
foreach (element_children($return) as $i) {

0 commit comments

Comments
 (0)