Skip to content
Snippets Groups Projects
Commit 68b99f1a authored by Adam G-H's avatar Adam G-H Committed by Chris Wells
Browse files

Issue #3457054: Identify projects in a more reliable way

parent 544ffd5a
No related branches found
No related tags found
1 merge request!528Use source_id/vendor/name as the identifier
Pipeline #208677 failed
......@@ -7,3 +7,4 @@ colinodell
testlogger
kanopi
tabwise
sophron
......@@ -630,7 +630,7 @@
.search__search_term::-webkit-search-decoration,
.search__search_term::-webkit-search-results-button,
.search__search_term::-webkit-search-results-decoration {
display: none;
display: none;
}
.search__search-bar {
......
......@@ -395,7 +395,7 @@ class InstallerController extends ControllerBase {
try {
$stage_id = $this->installer->create();
$this->setRequiringState($project->uuid, 'creating install stage', $stage_id);
$this->setRequiringState($project->id, 'creating install stage', $stage_id);
}
catch (\Exception $e) {
$this->cancelRequire();
......
......@@ -3,7 +3,6 @@
namespace Drupal\project_browser;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Config\ConfigCrudEvent;
use Drupal\Core\Config\ConfigEvents;
use Drupal\Core\Config\ConfigFactoryInterface;
......@@ -35,7 +34,6 @@ class EnabledSourceHandler implements LoggerAwareInterface, EventSubscriberInter
private readonly ConfigFactoryInterface $configFactory,
private readonly ProjectBrowserSourceManager $pluginManager,
private readonly ActivatorInterface $activator,
private readonly UuidInterface $uuid,
KeyValueExpirableFactoryInterface $keyValueFactory,
) {
$this->keyValue = $keyValueFactory->get('project_browser');
......@@ -117,10 +115,11 @@ class EnabledSourceHandler implements LoggerAwareInterface, EventSubscriberInter
$stored = [];
foreach ($projects as $source_id => $results) {
foreach ($results->list as $project) {
// Each project is identified by a UUID which persists until the data
// store is wiped.
$project->uuid = $this->uuid->generate();
$this->keyValue->set($project->uuid, $project);
// Generate an ID for the project from the package name and machine
// name, which are unlikely to change. This isn't security-sensitive,
// so SHA1 is okay for this purpose.
$project->id = sha1($source_id . $project->packageName . $project->machineName);
$this->keyValue->setIfNotExists($project->id, $project);
// Add activation data to the project.
$this->getActivationData($project);
}
......@@ -128,7 +127,7 @@ class EnabledSourceHandler implements LoggerAwareInterface, EventSubscriberInter
// ProjectsResultsPage.
$stored[$source_id] = [
$results->totalResults,
array_column($results->list, 'uuid'),
array_column($results->list, 'id'),
$results->pluginLabel,
];
}
......
......@@ -15,13 +15,13 @@ use Drupal\project_browser\ProjectType;
class Project implements \JsonSerializable {
/**
* A persistent UUID for this project in non-volatile storage.
* A persistent ID for this project in non-volatile storage.
*
* @var string
*
* @see \Drupal\project_browser\EnabledSourceHandler::getProjects()
*/
public string $uuid;
public string $id;
/**
* The status of this project in the current site.
......@@ -186,7 +186,7 @@ class Project implements \JsonSerializable {
'created' => $this->created,
'selector_id' => $this->getSelectorId(),
'commands' => $commands,
'id' => $this->uuid,
'id' => $this->id,
];
}
......
......@@ -625,7 +625,7 @@ class InstallerControllerTest extends BrowserTestBase {
foreach ($projects as $results_page) {
foreach ($results_page->list as $project) {
if ($project->machineName === $module_name) {
return $project->uuid;
return $project->id;
}
}
}
......
......@@ -274,7 +274,7 @@ class ProjectBrowserInstallerUiTest extends WebDriverTestBase {
if (method_exists($source, 'isProjectSafe') && !$source->isProjectSafe($project)) {
continue;
}
return $project->uuid;
return $project->id;
}
}
$this->fail("Could not find a project to install from amongst the enabled sources.");
......
......@@ -61,7 +61,7 @@ class EnabledSourceHandlerTest extends KernelTestBase {
$this->assertNotEmpty($list);
$project = reset($list);
$project_again = $handler->getStoredProject($project->uuid);
$project_again = $handler->getStoredProject($project->id);
$this->assertNotSame($project, $project_again);
$this->assertSame($project->jsonSerialize(), $project_again->jsonSerialize());
......@@ -86,7 +86,7 @@ class EnabledSourceHandlerTest extends KernelTestBase {
// `commands` properties should be uninitialized.
$project = $this->container->get('keyvalue.expirable')
->get('project_browser')
->get($project->uuid);
->get($project->id);
$this->assertInstanceOf(Project::class, $project);
$this->assertFalse(self::hasActivationData($project));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment