diff --git a/embargoes.install b/embargoes.install index f8ab0bb..fc77727 100644 --- a/embargoes.install +++ b/embargoes.install @@ -1,5 +1,7 @@ 'int', 'not null' => TRUE, ], - 'user' => [ + 'uid' => [ 'type' => 'int', 'not null' => TRUE, ], @@ -44,3 +46,13 @@ function embargoes_schema() { ]; return $schema; } + +/** + * Update the 'user' column to be called 'uid'. + */ +function embargoes_update_8001(&$sandbox) { + Database::getConnection()->schema()->changeField('embargoes_log', 'user', 'uid', [ + 'not null' => TRUE, + 'type' => 'int', + ]); +} diff --git a/src/Controller/EmbargoesLogController.php b/src/Controller/EmbargoesLogController.php index dd94496..ff7ad05 100644 --- a/src/Controller/EmbargoesLogController.php +++ b/src/Controller/EmbargoesLogController.php @@ -18,7 +18,7 @@ public function showRenderedLog() { foreach ($result as $record) { $formatted_time = date('c', $record->time); $node_title = \Drupal::entityTypeManager()->getStorage('node')->load($record->node)->get('title')->value; - $username = \Drupal\user\Entity\User::load($record->user)->getUsername(); + $username = \Drupal\user\Entity\User::load($record->uid)->getUsername(); if ($record->action == "deleted") { $embargo_formatted = Markup::create("{$record->embargo}"); } @@ -32,7 +32,7 @@ public function showRenderedLog() { 'time' => $formatted_time, 'action' => ucfirst($record->action), 'node' => Markup::create("$node_title"), - 'user' => Markup::create("$username"), + 'user' => Markup::create("$username"), ]; array_push($formatted_log, $row); } diff --git a/src/EmbargoesLogService.php b/src/EmbargoesLogService.php index 6b8ec4b..7a3ac31 100644 --- a/src/EmbargoesLogService.php +++ b/src/EmbargoesLogService.php @@ -15,10 +15,11 @@ public function __construct() { } public function logEmbargoEvent($values) { - $time = time(); - $database = \Drupal::database(); - $result = $database->query("INSERT INTO {embargoes_log} (time, action, node, user, embargo) VALUES ('{$time}', '{$values['action']}', '{$values['node']}', '{$values['user']}','{$values['embargo_id']}');"); - return $result; + $conn = \Drupal::database()->getConnection(); + $values['time'] = time(); + return $conn->insert('embargoes_log') + ->fields($values) + ->execute(); } } diff --git a/src/Form/EmbargoesEmbargoEntityDeleteForm.php b/src/Form/EmbargoesEmbargoEntityDeleteForm.php index 8876c42..1c73488 100644 --- a/src/Form/EmbargoesEmbargoEntityDeleteForm.php +++ b/src/Form/EmbargoesEmbargoEntityDeleteForm.php @@ -38,7 +38,7 @@ public function getConfirmText() { */ public function submitForm(array &$form, FormStateInterface $form_state) { $log_values['node'] = $this->entity->getEmbargoedNode(); - $log_values['user'] = \Drupal::currentUser()->id(); + $log_values['uid'] = \Drupal::currentUser()->id(); $log_values['embargo_id'] = $this->entity->id(); $log_values['action'] = 'deleted'; \Drupal::messenger()->addMessage("Your embargo has been {$log_values['action']}."); diff --git a/src/Form/EmbargoesEmbargoEntityForm.php b/src/Form/EmbargoesEmbargoEntityForm.php index 45668d4..537ed78 100644 --- a/src/Form/EmbargoesEmbargoEntityForm.php +++ b/src/Form/EmbargoesEmbargoEntityForm.php @@ -118,7 +118,7 @@ public function save(array $form, FormStateInterface $form_state) { $status = $embargo->save(); $log_values['node'] = $embargo->getEmbargoedNode(); - $log_values['user'] = \Drupal::currentUser()->id(); + $log_values['uid'] = \Drupal::currentUser()->id(); $log_values['embargo_id'] = $embargo->id(); if ($status == SAVED_NEW) { diff --git a/src/Form/EmbargoesNodeEmbargoesForm.php b/src/Form/EmbargoesNodeEmbargoesForm.php index 1ee575e..3d0594b 100644 --- a/src/Form/EmbargoesNodeEmbargoesForm.php +++ b/src/Form/EmbargoesNodeEmbargoesForm.php @@ -155,7 +155,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $embargo->save(); $log_values['node'] = $embargo->getEmbargoedNode(); - $log_values['user'] = \Drupal::currentUser()->id(); + $log_values['uid'] = \Drupal::currentUser()->id(); $log_values['embargo_id'] = $embargo->id(); if ($embargo_id == 'add') {