first commit
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/tombstone/DataObjectTombstone.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class DataObjectTombstone
|
||||
*
|
||||
* @ingroup tombstone
|
||||
*
|
||||
* @brief Base class for data object tombstones.
|
||||
*/
|
||||
|
||||
namespace PKP\tombstone;
|
||||
|
||||
use PKP\core\Core;
|
||||
|
||||
class DataObjectTombstone extends \PKP\core\DataObject
|
||||
{
|
||||
/**
|
||||
* get data object id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDataObjectId()
|
||||
{
|
||||
return $this->getData('dataObjectId');
|
||||
}
|
||||
|
||||
/**
|
||||
* set data object id
|
||||
*
|
||||
* @param int $dataObjectId
|
||||
*/
|
||||
public function setDataObjectId($dataObjectId)
|
||||
{
|
||||
$this->setData('dataObjectId', $dataObjectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* get date deleted
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateDeleted()
|
||||
{
|
||||
return $this->getData('dateDeleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* set date deleted
|
||||
*
|
||||
* @param string $dateDeleted
|
||||
*/
|
||||
public function setDateDeleted($dateDeleted)
|
||||
{
|
||||
$this->setData('dateDeleted', $dateDeleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stamp the date of the deletion to the current time.
|
||||
*/
|
||||
public function stampDateDeleted()
|
||||
{
|
||||
return $this->setDateDeleted(Core::getCurrentDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get oai setSpec.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSetSpec()
|
||||
{
|
||||
return $this->getData('setSpec');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set oai setSpec.
|
||||
*
|
||||
* @param string $setSpec
|
||||
*/
|
||||
public function setSetSpec($setSpec)
|
||||
{
|
||||
$this->setData('setSpec', $setSpec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get oai setName.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSetName()
|
||||
{
|
||||
return $this->getData('setName');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set oai setName.
|
||||
*
|
||||
* @param string $setName
|
||||
*/
|
||||
public function setSetName($setName)
|
||||
{
|
||||
$this->setData('setName', $setName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get oai identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOAIIdentifier()
|
||||
{
|
||||
return $this->getData('oaiIdentifier');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set oai identifier.
|
||||
*
|
||||
* @param string $oaiIdentifier
|
||||
*/
|
||||
public function setOAIIdentifier($oaiIdentifier)
|
||||
{
|
||||
$this->setData('oaiIdentifier', $oaiIdentifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an specific object id that is part of
|
||||
* the OAI set of this tombstone.
|
||||
*
|
||||
* @param int $assocType
|
||||
*
|
||||
* @return ?int The object id.
|
||||
*/
|
||||
public function getOAISetObjectId($assocType)
|
||||
{
|
||||
$setObjectsIds = $this->getOAISetObjectsIds();
|
||||
if (isset($setObjectsIds[$assocType])) {
|
||||
return $setObjectsIds[$assocType];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an specific object id that is part of
|
||||
* the OAI set of this tombstone.
|
||||
*
|
||||
* @param int $assocType
|
||||
* @param int $assocId
|
||||
*/
|
||||
public function setOAISetObjectId($assocType, $assocId)
|
||||
{
|
||||
$setObjectsIds = $this->getOAISetObjectsIds();
|
||||
$setObjectsIds[$assocType] = $assocId;
|
||||
|
||||
$this->setOAISetObjectsIds($setObjectsIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all objects ids that are part of
|
||||
* the OAI set of this tombstone.
|
||||
*
|
||||
* @return array assocType => assocId
|
||||
*/
|
||||
public function getOAISetObjectsIds()
|
||||
{
|
||||
return $this->getData('OAISetObjectsIds');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all objects ids that are part of
|
||||
* the OAI set of this tombstone.
|
||||
*
|
||||
* @param array $OAISetObjectsIds assocType => assocId
|
||||
*/
|
||||
public function setOAISetObjectsIds($OAISetObjectsIds)
|
||||
{
|
||||
$this->setData('OAISetObjectsIds', $OAISetObjectsIds);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\tombstone\DataObjectTombstone', '\DataObjectTombstone');
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/tombstone/DataObjectTombstoneDAO.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class DataObjectTombstoneDAO
|
||||
*
|
||||
* @ingroup tombstone
|
||||
*
|
||||
* @see DataObjectTombstone
|
||||
*
|
||||
* @brief Base class for retrieving and modifying DataObjectTombstone objects.
|
||||
*/
|
||||
|
||||
namespace PKP\tombstone;
|
||||
|
||||
use PKP\db\DAORegistry;
|
||||
|
||||
class DataObjectTombstoneDAO extends \PKP\db\DAO
|
||||
{
|
||||
/**
|
||||
* Return an instance of the DataObjectTombstone class.
|
||||
*
|
||||
* @return DataObjectTombstone
|
||||
*/
|
||||
public function newDataObject()
|
||||
{
|
||||
return new DataObjectTombstone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve DataObjectTombstone by id.
|
||||
*
|
||||
* @param int $tombstoneId
|
||||
* @param int $assocType
|
||||
* @param int $assocId
|
||||
*
|
||||
* @return DataObjectTombstone object
|
||||
*/
|
||||
public function getById($tombstoneId, $assocType = null, $assocId = null)
|
||||
{
|
||||
$params = [(int) $tombstoneId];
|
||||
if ($assocId !== null && $assocType !== null) {
|
||||
$params[] = (int) $assocType;
|
||||
$params[] = (int) $assocId;
|
||||
}
|
||||
$result = $this->retrieve(
|
||||
'SELECT DISTINCT * ' . $this->_getSelectTombstoneSql($assocType, $assocId),
|
||||
$params
|
||||
);
|
||||
$row = $result->current();
|
||||
return $row ? $this->_fromRow((array) $row) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve DataObjectTombstone by data object id.
|
||||
*
|
||||
* @param int $dataObjectId
|
||||
*
|
||||
* @return DataObjectTombstone object
|
||||
*/
|
||||
public function getByDataObjectId($dataObjectId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT * FROM data_object_tombstones WHERE data_object_id = ?',
|
||||
[(int) $dataObjectId]
|
||||
);
|
||||
$row = $result->current();
|
||||
return $row ? $this->_fromRow((array) $row) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a data object tombstone object from a row.
|
||||
*
|
||||
* @param array $row
|
||||
*
|
||||
* @return DataObjectTombstone object
|
||||
*/
|
||||
public function _fromRow($row)
|
||||
{
|
||||
$dataObjectTombstone = $this->newDataObject();
|
||||
$dataObjectTombstone->setId($row['tombstone_id']);
|
||||
$dataObjectTombstone->setDataObjectId($row['data_object_id']);
|
||||
$dataObjectTombstone->setDateDeleted($this->datetimeFromDB($row['date_deleted']));
|
||||
$dataObjectTombstone->setSetSpec($row['set_spec']);
|
||||
$dataObjectTombstone->setSetName($row['set_name']);
|
||||
$dataObjectTombstone->setOAIIdentifier($row['oai_identifier']);
|
||||
|
||||
$OAISetObjectsIds = $this->getOAISetObjectsIds($dataObjectTombstone->getId());
|
||||
$dataObjectTombstone->setOAISetObjectsIds($OAISetObjectsIds);
|
||||
|
||||
return $dataObjectTombstone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete DataObjectTombstone by tombstone id.
|
||||
*
|
||||
* @param int $tombstoneId
|
||||
* @param int $assocType
|
||||
* @param int $assocId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteById($tombstoneId, $assocType = null, $assocId = null)
|
||||
{
|
||||
$tombstone = $this->getById($tombstoneId, $assocType, $assocId);
|
||||
if (!$tombstone) {
|
||||
return false;
|
||||
} // Did not exist
|
||||
|
||||
assert($tombstone instanceof \PKP\tombstone\DataObjectTombstone);
|
||||
|
||||
if ($this->update(
|
||||
'DELETE FROM data_object_tombstones WHERE tombstone_id = ?',
|
||||
[(int) $tombstoneId]
|
||||
)) {
|
||||
$dataObjectTombstoneSettingsDao = DAORegistry::getDAO('DataObjectTombstoneSettingsDAO'); /** @var DataObjectTombstoneSettingsDAO $dataObjectTombstoneSettingsDao */
|
||||
$settingsDeleted = $dataObjectTombstoneSettingsDao->deleteSettings($tombstoneId);
|
||||
$setObjectsDeleted = $this->deleteOAISetObjects($tombstoneId);
|
||||
if ($settingsDeleted && $setObjectsDeleted) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete DataObjectTombstone by data object id.
|
||||
*
|
||||
* @param int $dataObjectId
|
||||
*/
|
||||
public function deleteByDataObjectId($dataObjectId)
|
||||
{
|
||||
$dataObjectTombstone = $this->getByDataObjectId($dataObjectId);
|
||||
if ($dataObjectTombstone) {
|
||||
$this->deleteById($dataObjectTombstone->getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a new data object tombstone into data_object_tombstone table.
|
||||
*
|
||||
* @param DataObjectTombstone $dataObjectTombstone
|
||||
*
|
||||
* @return int Data object tombstone id.
|
||||
*/
|
||||
public function insertObject(&$dataObjectTombstone)
|
||||
{
|
||||
$this->update(
|
||||
sprintf(
|
||||
'INSERT INTO data_object_tombstones
|
||||
(data_object_id, date_deleted, set_spec, set_name, oai_identifier)
|
||||
VALUES
|
||||
(?, %s, ?, ?, ?)',
|
||||
$this->datetimeToDB(date('Y-m-d H:i:s'))
|
||||
),
|
||||
[
|
||||
(int) $dataObjectTombstone->getDataObjectId(),
|
||||
$dataObjectTombstone->getSetSpec(),
|
||||
$dataObjectTombstone->getSetName(),
|
||||
$dataObjectTombstone->getOAIIdentifier()
|
||||
]
|
||||
);
|
||||
|
||||
$dataObjectTombstone->setId($this->getInsertId());
|
||||
$this->insertOAISetObjects($dataObjectTombstone);
|
||||
|
||||
return $dataObjectTombstone->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a data object tombstone in the data_object_tombstones table.
|
||||
*
|
||||
* @param DataObjectTombstone $dataObjectTombstone
|
||||
*
|
||||
* @return int dataObjectTombstone id
|
||||
*/
|
||||
public function updateObject($dataObjectTombstone)
|
||||
{
|
||||
$returner = $this->update(
|
||||
sprintf(
|
||||
'UPDATE data_object_tombstones SET
|
||||
data_object_id = ?,
|
||||
date_deleted = %s,
|
||||
set_spec = ?,
|
||||
set_name = ?,
|
||||
oai_identifier = ?
|
||||
WHERE tombstone_id = ?',
|
||||
$this->datetimeToDB(date('Y-m-d H:i:s'))
|
||||
),
|
||||
[
|
||||
(int) $dataObjectTombstone->getDataObjectId(),
|
||||
$dataObjectTombstone->getSetSpec(),
|
||||
$dataObjectTombstone->getSetName(),
|
||||
$dataObjectTombstone->getOAIIdentifier(),
|
||||
(int) $dataObjectTombstone->getId()
|
||||
]
|
||||
);
|
||||
|
||||
$this->updateOAISetObjects($dataObjectTombstone);
|
||||
|
||||
return $returner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all sets for data object tombstones that are inside of
|
||||
* the passed set object id.
|
||||
*
|
||||
* @param int $assocType The assoc type of the parent set object.
|
||||
* @param int $assocId The id of the parent set object.
|
||||
*
|
||||
* @return array('setSpec' => setName)
|
||||
*/
|
||||
public function &getSets($assocType, $assocId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT DISTINCT dot.set_spec AS set_spec, dot.set_name AS set_name FROM data_object_tombstones dot
|
||||
LEFT JOIN data_object_tombstone_oai_set_objects oso ON (dot.tombstone_id = oso.tombstone_id)
|
||||
WHERE oso.assoc_type = ? AND oso.assoc_id = ?',
|
||||
[(int) $assocType, (int) $assocId]
|
||||
);
|
||||
|
||||
$returner = [];
|
||||
foreach ($result as $row) {
|
||||
$returner[$row->set_spec] = $row->set_name;
|
||||
}
|
||||
return $returner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all objects ids that are part of the passed
|
||||
* tombstone OAI set.
|
||||
*
|
||||
* @param int $tombstoneId
|
||||
*
|
||||
* @return array assocType => assocId
|
||||
*/
|
||||
public function getOAISetObjectsIds($tombstoneId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT * FROM data_object_tombstone_oai_set_objects WHERE tombstone_id = ?',
|
||||
[(int) $tombstoneId]
|
||||
);
|
||||
|
||||
$oaiSetObjectsIds = [];
|
||||
foreach ($result as $row) {
|
||||
$oaiSetObjectsIds[$row->assoc_type] = $row->assoc_id;
|
||||
}
|
||||
return $oaiSetObjectsIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete OAI set objects data from data_object_tombstone_oai_set_objects table.
|
||||
*
|
||||
* @param int $tombstoneId The related tombstone id.
|
||||
*/
|
||||
public function deleteOAISetObjects($tombstoneId)
|
||||
{
|
||||
return $this->update(
|
||||
'DELETE FROM data_object_tombstone_oai_set_objects WHERE tombstone_id = ?',
|
||||
[(int) $tombstoneId]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert OAI set objects data into data_object_tombstone_oai_set_objects table.
|
||||
*
|
||||
* @param DataObjectTombstone $dataObjectTombstone
|
||||
*/
|
||||
public function insertOAISetObjects($dataObjectTombstone)
|
||||
{
|
||||
foreach ($dataObjectTombstone->getOAISetObjectsIds() as $assocType => $assocId) {
|
||||
$this->update(
|
||||
'INSERT INTO data_object_tombstone_oai_set_objects
|
||||
(tombstone_id, assoc_type, assoc_id)
|
||||
VALUES
|
||||
(?, ?, ?)',
|
||||
[
|
||||
(int) $dataObjectTombstone->getId(),
|
||||
(int) $assocType,
|
||||
(int) $assocId
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update OAI set objects data into data_object_tombstone_oai_set_objects table.
|
||||
*
|
||||
* @param DataObjectTombstone $dataObjectTombstone
|
||||
*/
|
||||
public function updateOAISetObjects($dataObjectTombstone)
|
||||
{
|
||||
foreach ($dataObjectTombstone->getOAISetObjectsIds() as $assocType => $assocId) {
|
||||
$this->update(
|
||||
'UPDATE data_object_tombstone_oai_set_objects SET
|
||||
assoc_type = ?,
|
||||
assoc_id = ?
|
||||
WHERE tombstone_id = ?',
|
||||
[
|
||||
(int) $assocType,
|
||||
(int) $assocId,
|
||||
(int) $dataObjectTombstone->getId()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Private helper methods.
|
||||
//
|
||||
|
||||
/**
|
||||
* Get the sql to select a tombstone from table, optionally
|
||||
* using an OAI set object id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function _getSelectTombstoneSql($assocType, $assocId)
|
||||
{
|
||||
return 'FROM data_object_tombstones dot
|
||||
LEFT JOIN data_object_tombstone_oai_set_objects oso ON (dot.tombstone_id = oso.tombstone_id)
|
||||
WHERE dot.tombstone_id = ?' .
|
||||
(isset($assocId) && isset($assocType) ? 'AND oso.assoc_type = ? AND oso.assoc_id = ?' : '');
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\tombstone\DataObjectTombstoneDAO', '\DataObjectTombstoneDAO');
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/tombstone/DataObjectTombstoneSettingsDAO.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class DataObjectTombstoneSettingsDAO
|
||||
*
|
||||
* @ingroup submission
|
||||
*
|
||||
* @brief Operations for retrieving and modifying submission tombstone settings.
|
||||
*/
|
||||
|
||||
namespace PKP\tombstone;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DataObjectTombstoneSettingsDAO extends \PKP\db\DAO
|
||||
{
|
||||
/**
|
||||
* Retrieve an submission tombstone setting value.
|
||||
*
|
||||
* @param int $tombstoneId
|
||||
* @param string $name
|
||||
* @param string $locale optional
|
||||
*/
|
||||
public function getSetting($tombstoneId, $name, $locale = null)
|
||||
{
|
||||
$params = [(int) $tombstoneId, $name];
|
||||
if ($locale !== null) {
|
||||
$params[] = $locale;
|
||||
}
|
||||
$result = $this->retrieve(
|
||||
'SELECT setting_value, setting_type, locale FROM data_object_tombstone_settings WHERE tombstone_id = ? AND setting_name = ?'
|
||||
. ($locale !== null ? ' AND locale = ?' : ''),
|
||||
$params
|
||||
);
|
||||
|
||||
$setting = null;
|
||||
foreach ($result as $row) {
|
||||
$value = $this->convertFromDB($row->setting_value, $row->setting_type);
|
||||
if (!isset($row->locale) || $row->locale == '') {
|
||||
$setting[$name] = $value;
|
||||
} else {
|
||||
$setting[$name][$row->locale] = $value;
|
||||
}
|
||||
}
|
||||
return $setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/update an submission tombstone setting.
|
||||
*
|
||||
* @param int $tombstoneId
|
||||
* @param string $name
|
||||
* @param string $type data type of the setting. If omitted, type will be guessed
|
||||
* @param bool $isLocalized
|
||||
*/
|
||||
public function updateSetting($tombstoneId, $name, $value, $type = null, $isLocalized = false)
|
||||
{
|
||||
if (!$isLocalized) {
|
||||
$value = $this->convertToDB($value, $type);
|
||||
DB::table('data_object_tombstone_settings')->updateOrInsert(
|
||||
['tombstone_id' => $tombstoneId, 'setting_name' => $name, 'locale' => ''],
|
||||
['setting_value' => $value, 'setting_type' => $type]
|
||||
);
|
||||
}
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $locale => $localeValue) {
|
||||
$this->update(
|
||||
'DELETE FROM data_object_tombstone_settings WHERE tombstone_id = ? AND setting_name = ? AND locale = ?',
|
||||
[(int) $tombstoneId, $name, $locale]
|
||||
);
|
||||
if (empty($localeValue)) {
|
||||
continue;
|
||||
}
|
||||
$type = null;
|
||||
$this->update(
|
||||
'INSERT INTO data_object_tombstone_settings
|
||||
(tombstone_id, setting_name, setting_value, setting_type, locale)
|
||||
VALUES (?, ?, ?, ?, ?)',
|
||||
[(int) $tombstoneId, $name, $this->convertToDB($localeValue, $type), $type, $locale]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an submission tombstone setting.
|
||||
*
|
||||
* @param int $tombstoneId
|
||||
* @param string $name
|
||||
* @param string $locale optional
|
||||
*
|
||||
* @return int Affected row count
|
||||
*/
|
||||
public function deleteSetting($tombstoneId, $name, $locale = null)
|
||||
{
|
||||
$params = [(int) $tombstoneId, $name];
|
||||
$sql = 'DELETE FROM data_object_tombstone_settings WHERE tombstone_id = ? AND setting_name = ?';
|
||||
if ($locale !== null) {
|
||||
$params[] = $locale;
|
||||
$sql .= ' AND locale = ?';
|
||||
}
|
||||
return $this->update($sql, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all settings for an submission tombstone.
|
||||
*
|
||||
* @param int $tombstoneId
|
||||
*
|
||||
* @return int Affected row count
|
||||
*/
|
||||
public function deleteSettings($tombstoneId)
|
||||
{
|
||||
return $this->update(
|
||||
'DELETE FROM data_object_tombstone_settings WHERE tombstone_id = ?',
|
||||
[(int) $tombstoneId]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\tombstone\DataObjectTombstoneSettingsDAO', '\DataObjectTombstoneSettingsDAO');
|
||||
}
|
||||
Reference in New Issue
Block a user