Skip to content
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

Accession counter incrementing fix, refs #11700 #681

Merged
merged 1 commit into from
Mar 20, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 20 additions & 3 deletions plugins/qtAccessionPlugin/lib/model/QubitAccession.php
Expand Up @@ -26,10 +26,21 @@ public function __toString()

protected function insert($connection = null)
{
// If no identifier has been specified, use next available one
if (!$this->identifier)
// If identifier has been specified and the mask is enabled, increment the counter
if (!empty($this->identifier) && self::maskEnabled())
{
$this->identifier = self::nextAvailableIdentifier();
$con = Propel::getConnection();
try
{
$con->beginTransaction();
self::incrementAccessionCounter();
$con->commit();
}
catch (PropelException $e)
{
$con->rollback();
throw $e;
}
}

if (!isset($this->slug))
Expand Down Expand Up @@ -81,6 +92,12 @@ public function isAccrual()
return 0 < count(QubitRelation::get($criteria));
}

public static function maskEnabled()
{
$setting = QubitSetting::getByName('accession_mask_enabled');
return (null === $setting || boolval($setting->getValue(array('sourceCulture' => true))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels wrong to me, are we sure that if the setting is missing (a rare case) we should consider that the mask is enabled? Otherwise, we could use sfConfig to get its value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setting doesn't get created by a migration, alas, and the default behaviour IIRC is to use the mask.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice! Thanks

}

public static function nextAccessionNumber()
{
$setting = QubitSetting::getByName('accession_counter');
Expand Down
Expand Up @@ -183,10 +183,7 @@ protected function addField($name)
$this->form->setDefault('identifier', $this->resource['identifier']);

// If accession mask enable setting isn't set or is set to on, then populate default with mask value
$accessionMaskEnabledSetting = QubitSetting::getByName('accession_mask_enabled');
$accessionMaskEnabled = (null === $accessionMaskEnabledSetting || boolval($accessionMaskEnabledSetting->getValue(array('sourceCulture'=>true))));

if (!isset($this->resource->id) && $accessionMaskEnabled)
if (!isset($this->resource->id) && QubitAccession::maskEnabled())
{
$dt = new DateTime;
$this->form->setDefault('identifier', QubitAccession::nextAvailableIdentifier());
Expand Down