Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Deeson/WardenDrupalBundle/Document/SiteDrupalDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public function setSiteId($siteId) {
* @return string
*/
public function getTypeImagePath() {
if ($this->getCoreVersion() < 8) {
return 'bundles/deesonwardendrupal/images/drupal7-logo.png';
}
// Grab first digits before first dot
preg_match("/^(\d)*?\./", $this->getCoreVersion(), $matches);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it fails with Drupal 10, because the regex would capture only 0, skipping 1.
I suggest to use /^(\d+)\./. It's also easier to read.
Another alternative would be:

$version = $explode('.', $this->getCoreVersion())[0];
$version = empty($version) ? 8 : $version;


// If none found, defaults to drupal 8
$version = (isset($matches[1])) ? $matches[1] : 8;

return 'bundles/deesonwardendrupal/images/drupal8-logo.png';
return 'bundles/deesonwardendrupal/images/drupal' . $version . '-logo.png';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public function processRequestData($requestData) {
$recommendedMajorVersion = (string) $requestXmlObject->recommended_major;
$supportedMajor = (string) $requestXmlObject->supported_majors;
$supportedMajorVersions = explode(',', $supportedMajor);
} else {
// TODO This will need to be reworked once Drupal 10 is out
// In the current xml file, supported_majors key doesn't exist
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad intendation.

$recommendedMajorVersion = (string) 9;
$supportedMajorVersions = [9];
}

$latestReleaseVersions = array();
Expand All @@ -210,6 +215,10 @@ public function processRequestData($requestData) {
/*if (!is_null($versionInfo['extra'])) {
continue;
}*/
}elseif(preg_match('/^(' . implode('|', $supportedMajorVersions) . ')/', $release->version, $matches)){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style problems with spacing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This RX is hard to read.
I suggest:

$rx = implode('|', $supportedMajorVersions);
$rx = "/^($rx)/";
...
} elseif (preg_match($rx, $release->version, $matches)) {

$key = array_search($matches[1], $supportedMajorVersions);
$release->version_major = $matches[1];
$latestReleaseVersions[$supportedMajorVersions[$key]][] = $release;
}
}
}
Expand Down Expand Up @@ -246,7 +255,14 @@ public function processRequestData($requestData) {
* @return mixed
*/
protected function getRequestUrl() {
return 'https://updates.drupal.org/release-history/' . $this->moduleRequestName . '/' . $this->moduleRequestVersion;
// TODO This might change in the future
// drupal update release history for 9.x doesn't exist, we need to use /current for now
// might change in the future
if ($this->moduleRequestName == 'drupal' && $this->moduleRequestVersion == '9.x') {
return 'https://updates.drupal.org/release-history/' . $this->moduleRequestName . '/current';
} else {
return 'https://updates.drupal.org/release-history/' . $this->moduleRequestName . '/' . $this->moduleRequestVersion;
}
}

/**
Expand Down Expand Up @@ -292,13 +308,16 @@ protected function updateContribModules() {

/** @var DrupalModuleDocument $module */
foreach ($modules as $module) {
if (empty($module->getProjectName()))
continue;

$this->logger->addInfo('Updating - ' . $module->getProjectName() . ' for version: ' . $version);

try {
$this->processDrupalUpdateData($module->getProjectName(), $version);
}
catch (\Exception $e) {
$this->logger->addWarning(' - Unable to update module version [' . $version . ']: ' . $e->getMessage());
$this->logger->addWarning(' - Unable to update module ' . $module->getProjectName() . ' version [' . $version . ']: ' . $e->getMessage());
continue;
}

Expand Down