object_log.module in Object Log 8
Same filename and directory in other branches
File
object_log.moduleView source
<?php
/**
* Store a variable in the object log.
*
* @param $label
* A name to use for this object when storing in the log table. Using an
* already existing label will overwrite that object in the log.
* @param $data
* The variable to store.
*/
function object_log($label, $data) {
$fields = array(
'data' => serialize($data),
'created' => \Drupal::time()
->getRequestTime(),
);
\Drupal::database()
->merge('object_log')
->keys(array(
'label' => $label,
))
->fields($fields)
->execute();
}
/**
* Retrieve an object row from the object log.
*
* @param $label
* The label of an object to be retrieved.
* @return
* The database row as a fetched object. $log->data contains the actual
* stored object.
*/
function object_log_retrieve($label) {
$result = \Drupal::database()
->query('SELECT label, data, created FROM {object_log} WHERE label = :label', array(
':label' => $label,
));
$log = $result
->fetchObject();
if (empty($log->data)) {
return FALSE;
}
$log->data = unserialize($log->data);
return $log;
}
/**
* Clear the object log.
*/
function object_log_clear_log() {
\Drupal::database()
->delete('object_log')
->execute();
}
Functions
Name | Description |
---|---|
object_log | Store a variable in the object log. |
object_log_clear_log | Clear the object log. |
object_log_retrieve | Retrieve an object row from the object log. |