Merge branch 'master' of ssh://git.autonomic.zone:2222/autonomic-cooperative/opencase
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace Drupal\opencase;
|
||||
use Drupal;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\opencase\Utils;
|
||||
|
||||
final class TimeBasedFieldUpdater {
|
||||
|
||||
@ -12,24 +13,25 @@ final class TimeBasedFieldUpdater {
|
||||
private array $conditions;
|
||||
private string $date_format;
|
||||
|
||||
final public function __construct(EntityTypeManagerInterface $entityTypeManager, string $entity_type, string $date_field, array $conditions = [], string $date_format = 'Y-m-d')
|
||||
final public function __construct(
|
||||
EntityTypeManagerInterface $entityTypeManager,
|
||||
Utils $utils,
|
||||
string $entity_type, string $bundle, string $date_field, string $date_format = 'Y-m-d'
|
||||
)
|
||||
{
|
||||
$this->entityTypeManager = $entityTypeManager;
|
||||
$this->utils = $utils;
|
||||
$this->date_field = $date_field;
|
||||
$this->conditions = $conditions;
|
||||
$this->date_format = $date_format;
|
||||
$this->entity_type = $entity_type;
|
||||
$this->bundle = $bundle;
|
||||
}
|
||||
|
||||
final public function update(string $time_elapsed, array $old_values, array $new_values): void {
|
||||
final public function update(array $conditions, string $time_elapsed, array $new_values): void {
|
||||
$query = $this->entityTypeManager->getStorage($this->entity_type)->getQuery();
|
||||
foreach($this->conditions as $cond_field=>$cond_value) {
|
||||
$query->condition($cond_field, $cond_value);
|
||||
}
|
||||
foreach($old_values as $old_field=>$old_value) {
|
||||
$query->condition($old_field, $old_value);
|
||||
}
|
||||
$query->condition($this->date_field, date($this->date_format, strtotime('-'.$time_elapsed)), "<");
|
||||
$conditions[] = [$this->date_field, date($this->date_format, strtotime('-'.$time_elapsed)), "<"];
|
||||
$conditions[] = ['type', $this->bundle, '='];
|
||||
$this->utils->addConditionsToQuery($query, $conditions);
|
||||
foreach($query->execute() as $id) {
|
||||
$entity = $this->entityTypeManager->getStorage($this->entity_type)->load($id);
|
||||
foreach($new_values as $new_field=>$new_value) {
|
||||
|
Reference in New Issue
Block a user