Skip to content

Commit

Permalink
Merge pull request #243 from silverstripe-terraformers/feature/after-…
Browse files Browse the repository at this point in the history
…mutation

Operation extension points
  • Loading branch information
robbieaverill committed Dec 14, 2019
2 parents 87ee85a + ec84920 commit 0a9913f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public function addMiddleware($middleware)
*/
protected function callMiddleware(Schema $schema, $query, $context, $params, callable $last)
{
$this->extend('onBeforeCallMiddleware', $schema, $query, $context, $params);

// Reverse middlewares
$next = $last;
// Filter out any middlewares that are set to `false`, e.g. via config
Expand All @@ -138,7 +140,12 @@ protected function callMiddleware(Schema $schema, $query, $context, $params, cal
return $middleware->process($schema, $query, $context, $params, $next);
};
}
return $next($schema, $query, $context, $params);

$result = $next($schema, $query, $context, $params);

$this->extend('onAfterCallMiddleware', $schema, $query, $context, $params);

return $result;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Scaffolding/Scaffolders/CRUD/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public function resolve($object, array $args, $context, ResolveInfo $info)

// Save and return
$newObject->write();
return DataObject::get_by_id($this->getDataObjectClass(), $newObject->ID);
$newObject = DataObject::get_by_id($this->getDataObjectClass(), $newObject->ID);

$this->extend('afterMutation', $newObject, $args, $context, $info);

return $newObject;
}
}
4 changes: 3 additions & 1 deletion src/Scaffolding/Scaffolders/CRUD/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function generateInputType()

public function resolve($object, array $args, $context, ResolveInfo $info)
{
DB::get_conn()->withTransaction(function () use ($args, $context) {
DB::get_conn()->withTransaction(function () use ($args, $context, $info) {
// Build list to filter
$results = DataList::create($this->getDataObjectClass())
->byIDs($args['IDs']);
Expand Down Expand Up @@ -93,6 +93,8 @@ public function resolve($object, array $args, $context, ResolveInfo $info)
foreach ($resultsList as $obj) {
$obj->delete();
}

$this->extend('afterMutation', $resultsList, $args, $context, $info);
});
}
}
3 changes: 3 additions & 0 deletions src/Scaffolding/Scaffolders/CRUD/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public function resolve($object, array $args, $context, ResolveInfo $info)

$obj->update($input);
$obj->write();

$this->extend('afterMutation', $obj, $args, $context, $info);

return $obj;
}
}

0 comments on commit 0a9913f

Please sign in to comment.