Skip to content

Instantly share code, notes, and snippets.

@tractorcow
Created May 4, 2017 02:02
Show Gist options
  • Save tractorcow/540a3056cfce5d45f0d5c680372dad0c to your computer and use it in GitHub Desktop.
Save tractorcow/540a3056cfce5d45f0d5c680372dad0c to your computer and use it in GitHub Desktop.
diff --git a/src/Security/InheritedPermissions.php b/src/Security/InheritedPermissions.php
index ae8d203..66a1987 100644
--- a/src/Security/InheritedPermissions.php
+++ b/src/Security/InheritedPermissions.php
@@ -212,6 +212,10 @@ class InheritedPermissions
foreach ([ Versioned::DRAFT, Versioned::LIVE ] as $stage) {
$stageRecords = Versioned::get_by_stage($this->getBaseClass(), $stage)
->byIDs($ids);
+ // Exclude previously calculated records from later stage calculations
+ if ($combinedStageResult) {
+ $stageRecords = $stageRecords->exclude('ID', array_keys($combinedStageResult));
+ }
$stageResult = $this->batchPermissionCheckForStage(
$type,
$globalPermission,
@tractorcow
Copy link
Author

3.x has a slightly different code style. You'll need to use direct SQL queries.

if($ids) {
	$idQuery = "SELECT \"ID\" FROM \"$table\" WHERE \"ID\" IN ($idPlaceholders)";
	$idArgs = $ids;
	if ($combinedStageResult) {
		$combinedPlaceholders = DB::placeholders($combinedStageResult);
		$idQuery .= " AND \"ID\" NOT IN ($combinedPlaceholders)";
		$idArgs = array_values($ids) + array_keys($combinedStageResult);
	}
	$stageIds = DB::prepared_query($idQuery, $idArgs)->column();
}

@tractorcow
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment