Skip to content

Commit

Permalink
Fixes sorting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstandiford committed Dec 17, 2021
1 parent ab04622 commit 42f2e03
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions lib/Factories/Dependency_Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,19 @@ public function filter_dependencies() {
/* @var Item_With_Dependencies $item */
$item = $queue[0];

// If this item has no dependencies, add it right away.
if ( empty( $item->get_dependencies() ) ) {
$items[] = $item;
$queued_deps[] = $item->get_id();
array_shift( $queue );
continue;
}

// If this item depends on something that doesn't exist, skip it.
$unmet_dependencies = array_diff( $this->get_dependencies( $item ), $dependency_ids );

if ( ! empty( $unmet_dependencies ) ) {
Logger::log(
'debug',
'observer_detached',
'An event was detached because it has unmet dependencies',
[
'item_id' => $item->id,
'unmet_dependencies' => $unmet_dependencies,
]
);
Logger::log(
'debug',
'observer_detached',
'An event was detached because it has unmet dependencies',
[
'item_id' => $item->id,
'unmet_dependencies' => $unmet_dependencies,
]
);
array_shift( $queue );
continue;
}
Expand All @@ -79,12 +71,16 @@ public function filter_dependencies() {
// If all dependencies have been added, add this after the last dependency
if ( empty( $dependencies_not_added_yet ) ) {
$last_dependency_key = $this->get_last_dependency( $item, $items );
$items = array_merge(
array_slice( $items, 0, $last_dependency_key + 1 ),
[ $item ],
array_slice( $items, $last_dependency_key + 1, count( $items ) - $last_dependency_key + 1 )
);
$queued_deps[] = $item->get_id();
if(0 === $last_dependency_key){
array_unshift($items, $item);
} else {
$items = array_merge(
array_slice( $items, 0, $last_dependency_key + 1 ),
[ $item ],
array_slice( $items, $last_dependency_key + 1, count( $items ) - $last_dependency_key + 1 )
);
}
$queued_deps[] = $item->get_id();
array_shift( $queue );
}
}
Expand Down

0 comments on commit 42f2e03

Please sign in to comment.