Drupal.org packaging has a $conditions arguments in release packaging for parent_commit: https://git.drupalcode.org/project/drupalorg/blob/dev/drupalorg_project/...

Making this possible with EntityFieldQuery will help move #2905986: Move away from custom conditions on controllers along.

CommentFileSizeAuthor
#5 3070937.patch2.06 KBdrumm
#3 3070937.patch1.9 KBdrumm
#2 3070937.patch1.85 KBdrumm

Comments

drumm created an issue. See original summary.

drumm’s picture

Title: Allow EntityFieldQuery on parent_commit » Allow EntityFieldQuery on versioncontrol_git_operations columns
Assigned: Unassigned » drumm
Status: Active » Needs review
Issue tags: +affects drupal.org
StatusFileSize
new1.85 KB

This allows conditions on all of the columns in versioncontrol_git_operations, including author_name, committer_name, parent_commit, and merge. For example:

$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'versioncontrol_operation')
  ->propertyCondition('repo_id', $project_node->versioncontrol_project['repo_id'])
  ->propertyCondition('parent_commit', $release_node_wrapper->field_packaged_git_sha1->value())
  ->execute();
drumm’s picture

StatusFileSize
new1.9 KB

Slight coding standards improvement.

marvil07’s picture

@drumm, thanks for the patch!
Indeed, it is a good idea to expose data to entity field query.

The change looks good, I still need to test it, but I have one question:

+  if (!isset($query->getTables()['versioncontrol_git_operations'])) {
+    $query->join('versioncontrol_git_operations', 'versioncontrol_git_operations', array_keys($query->getTables())[0] . '.vc_op_id = versioncontrol_git_operations.vc_op_id');
+  }

A QueryAlterableInterface is passed to hook_query_TAG_alter(), and I see getTables() is used, which seems to come from SelectQueryInterface.
Is there a reason to assume that the received object implements SelectQueryInterface?
In most cases this is probably not a problem, but just to be on the safe side, we may want to add a condition like if ($query instanceof SelectQueryInterface) before using it; it may also be that d7 OOP was not strict enough and some things are a bit assumed.

I may be missing something here, so please let me know if that is the case.

drumm’s picture

StatusFileSize
new2.06 KB

EntityFieldQuery will pass ->addTag('versioncontrol_git_operations') into the select query it constructs, so it should always be a SelectQueryInterface, in this case. There could be a query tag collision, and something else adds that tag to a different query type.

This patch adds this to fail noisily if that happens:

if (!($query instanceof SelectQueryInterface)) {
  throw new Exception(t('The "versioncontrol_git_operations" query tag only supports select queries.'));
}

  • marvil07 committed 4cd03a9 on 7.x-1.x
    Issue #3070937: Add a minimal test on EntityFieldQuery integration for...
  • marvil07 committed 5fe5907 on 7.x-1.x authored by drumm
    Issue #3070937 by drumm: Allow EntityFieldQuery on...
marvil07’s picture

Status: Needs review » Fixed

@drumm, thanks for the added change!
I did a small manual test, and then I added a minimal test case.
This is now added to 7.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.