<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
silverstripe-terraformers / open-archive-initiative-repository example snippets
private static array $oai_fields = [
// Key = the OAI field name (Title)
// Value = a property on your model (Title)
'Title' => 'Title',
// Key = the OAI field name (Description)
// Value = a method in your model (getDescription)
'Description' => 'getDescription',
];
namespace App\Tasks;
... imports
class CreateInitialOaiRecords extends BuildTask
{
private static $segment = 'create-initial-oai-records'; // phpcs:ignore
protected $title = 'Create Initial OAI Records'; // phpcs:ignore
protected $description = 'Create/update OAI Records for all Pages and Documents'; // phpcs:ignore
/**
* @param HTTPRequest $request
* @return void
*/
public function run($request) // phpcs:ignore SlevomatCodingStandard.TypeHints
{
$classes = [
Page::class,
File::class,
];
foreach ($classes as $class) {
// Set our stage to LIVE so that we only fetch DataObjects that are available on the frontend. This isn't
// totally necessary since the Queued Job will validate this itself, but it saves us from queueing Jobs that
// we know we don't need
/** @var DataList|OaiRecordManager[] $dataObjects */
$dataObjects = Versioned::withVersionedMode(static function () use ($class): DataList {
Versioned::set_stage(Versioned::LIVE);
return DataObject::get($class);
});
// Easy as, just triggerOaiRecordUpdate(). This method + the queued job will take care of the rest
foreach ($dataObjects as $dataObject) {
$dataObject->triggerOaiRecordUpdate();
}
}
echo 'Finished queueing OAI Record update Jobs';
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.