Skip to content

Add events on setting insert, update, and delete #2291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion application/src/Settings/AbstractSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
namespace Omeka\Settings;

use Doctrine\DBAL\Connection;
use Laminas\EventManager\EventManagerAwareInterface;
use Laminas\EventManager\EventManagerAwareTrait;
use Omeka\Mvc\Status;

abstract class AbstractSettings implements SettingsInterface
abstract class AbstractSettings implements SettingsInterface, EventManagerAwareInterface
{
use EventManagerAwareTrait;

/**
* @var Connection
*/
Expand Down Expand Up @@ -173,17 +177,26 @@ protected function setSetting($id, $value)
['id' => $id],
['json_array']
);
$this->getEventManager()->trigger('setting.update', $this, [
'id' => $id,
'value' => $value,
]);
} else {
$this->connection->insert(
$this->getTableName(),
['value' => $value, 'id' => $id],
['json_array']
);
$this->getEventManager()->trigger('setting.insert', $this, [
'id' => $id,
'value' => $value,
]);
}
}

protected function deleteSetting($id)
{
$this->connection->delete($this->getTableName(), ['id' => $id]);
$this->getEventManager()->trigger('setting.delete', $this, ['id' => $id]);
}
}
10 changes: 10 additions & 0 deletions application/src/Settings/AbstractTargetSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,22 @@ protected function setSetting($id, $value)
['id' => $id, $this->getTargetIdColumnName() => $this->targetId],
['json_array']
);
$this->getEventManager()->trigger('setting.update', $this, [
'target_id' => $this->targetId,
'id' => $id,
'value' => $value,
]);
} else {
$this->connection->insert(
$this->getTableName(),
['value' => $value, $this->getTargetIdColumnName() => $this->targetId, 'id' => $id],
['json_array', \PDO::PARAM_INT]
);
$this->getEventManager()->trigger('setting.insert', $this, [
'target_id' => $this->targetId,
'id' => $id,
'value' => $value,
]);
}
}

Expand Down