Skip to content
Snippets Groups Projects
Commit 4d812948 authored by Laurent's avatar Laurent
Browse files

hotline#123615 refactoring save in Journal_Type

parent 17d8e5de
No related merge requests found
Pipeline #12019 passed with stage
in 51 minutes and 27 seconds
......@@ -29,18 +29,15 @@ class Class_Journal_AdminVarType extends Class_Journal_Type {
NEW_VALUE = 'new_value';
public static function save($model) {
if (!$model)
return;
public function save($model) {
if (!parent::save($model))
return false;
if (!$journal = static::_newJournal())
return;
$this->_journal->addDetail(static::ADMINVAR_ID, $model->getClef());
$this->_journal->addDetail(static::PREVIOUS_VALUE, $model->getPreviousValue());
$this->_journal->addDetail(static::NEW_VALUE, $model->getValeur());
$journal->addDetail(static::ADMINVAR_ID, $model->getClef());
$journal->addDetail(static::PREVIOUS_VALUE, $model->getPreviousValue());
$journal->addDetail(static::NEW_VALUE, $model->getValeur());
return $journal;
return true;
}
......
......@@ -27,13 +27,15 @@ class Class_Journal_CatalogueType extends Class_Journal_Type {
PREVIOUS_VALUE = 'previous_value',
NEW_VALUE = 'new_value';
public static function save($model) {
$journal = static::_newJournal();
$journal->addDetail(static::MODEL_ID, $model->getId());
$journal->addDetail(static::PREVIOUS_VALUE, json_encode($model->getRawDbAttributes()));
$journal->addDetail(static::NEW_VALUE, json_encode($model->getRawAttributes()));
$journal
->save();
public function save($model) {
if (!parent::save($model))
return false;
$this->_journal->addDetail(static::MODEL_ID, $model->getId());
$this->_journal->addDetail(static::PREVIOUS_VALUE, json_encode($model->getRawDbAttributes()));
$this->_journal->addDetail(static::NEW_VALUE, json_encode($model->getRawAttributes()));
return true;
}
public function getLabel(){
......
......@@ -26,33 +26,26 @@ class Class_Journal_ProfileType extends Class_Journal_Type {
MY_TYPE = 'PROFILE_SAVE',
MODEL_ID = 'model_id',
PREVIOUS_VALUE = 'previous_value',
NEW_VALUE = 'new_value',
STACK = 'stack';
NEW_VALUE = 'new_value';
public static function save($model) {
if (!$model)
return;
public function save($model) {
if (!parent::save($model))
return false;
$this->_journal->addDetail(static::MODEL_ID, $model->getId());
$current = $model->getRawAttributes();
$previous = $model->getRawDbAttributes();
if (!isset($previous['cfg_accueil']))
return;
if (!$journal = static::_newJournal())
return;
$this->_journal->addDetail(static::NEW_VALUE, json_encode(static::_unserialize($current['cfg_accueil'])));
$journal->addDetail(static::MODEL_ID, $model->getId());
$journal->addDetail(static::PREVIOUS_VALUE, json_encode(static::_unserialize($previous['cfg_accueil'])));
$journal->addDetail(static::NEW_VALUE, json_encode(static::_unserialize($current['cfg_accueil'])));
if (!isset($previous['cfg_accueil']))
return true;
ob_start();
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$stack = ob_get_contents();
ob_end_clean();
$journal->addDetail(static::STACK, $stack);
$this->_journal->addDetail(static::PREVIOUS_VALUE, json_encode(static::_unserialize($previous['cfg_accueil'])));
return $journal;
return true;
}
......
......@@ -26,7 +26,8 @@ class Class_Journal_Type {
const
MY_TYPE = 'UNKNOWN',
MAX_STACK = 100,
CURRENT_USER_ID = 'current_user_id';
CURRENT_USER_ID = 'current_user_id',
STACK = 'stack';
protected static $_enabled = true;
......@@ -65,29 +66,33 @@ class Class_Journal_Type {
}
protected static function _newJournal() {
$journal = Class_Journal::newInstance(['type' => static::MY_TYPE]);
public function save($model) {
if (!$this->_journal->save())
return false;
$this->_cleanStack();
if (!$journal->save())
return;
$this->_journal->addDetail(static::CURRENT_USER_ID,
($user = Class_Users::getIdentity()) ? $user->getId() : '');
static::_cleanStack();
ob_start();
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$stack = ob_get_contents();
ob_end_clean();
$this->_journal->addDetail(static::STACK, $stack);
$journal->addDetail(static::CURRENT_USER_ID,
($user = Class_Users::getIdentity()) ? $user->getId() : '');
return $journal;
return true;
}
protected static function _cleanStack() {
protected function _cleanStack() {
while (static::MAX_STACK < Class_Journal::countBy(['type' => static::MY_TYPE]))
Class_Journal::findFirstBy(['order' => 'created_at'])->delete();
}
public function __construct($journal) {
$this->_journal = $journal;
$this->_journal = $journal->setType(static::MY_TYPE);
}
......
......@@ -210,7 +210,7 @@ class JournalProfilePostTest extends JournalProfileTestCase {
/** @test */
public function journalShouldHaveStackDetail() {
$this->assertContains('#0 Class_Journal_ProfileType::save()',
$this->assertContains('#0 Class_Journal_Type->save()',
Class_JournalDetail::findFirstBy(['type' => 'stack'])->getValue());
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment