-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from griidc/release/5.8.0
Release/5.8.0
- Loading branch information
Showing
11 changed files
with
274 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Pelagos\Migrations; | ||
|
||
use Doctrine\DBAL\Migrations\AbstractMigration; | ||
use Doctrine\DBAL\Schema\Schema; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
class Version20181107205545 extends AbstractMigration | ||
{ | ||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function up(Schema $schema) | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); | ||
|
||
$this->addSql('ALTER TABLE dataset ADD accepted_date TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE dataset_audit ADD accepted_date TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL'); | ||
} | ||
|
||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function down(Schema $schema) | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); | ||
|
||
$this->addSql('ALTER TABLE dataset DROP accepted_date'); | ||
$this->addSql('ALTER TABLE dataset_audit DROP accepted_date'); | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
src/Pelagos/Bundle/AppBundle/Command/BackFillAcceptedDateDatasetCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
|
||
namespace Pelagos\Bundle\AppBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use Pelagos\Entity\Dataset; | ||
|
||
/** | ||
* Back fill script for accepted date for Dataset entity. | ||
* | ||
* @see ContainerAwareCommand | ||
*/ | ||
class BackFillAcceptedDateDatasetCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* Configures the current command. | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('dataset:backfill-accepted-date') | ||
->setDescription('Backfill Dataset accepted date for approved datasets.'); | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param InputInterface $input An InputInterface instance. | ||
* @param OutputInterface $output An OutputInterface instance. | ||
* | ||
* @return void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); | ||
|
||
$datasets = $entityManager->getRepository(Dataset::class)->findBy(array('datasetStatus' => Dataset::DATASET_STATUS_ACCEPTED)); | ||
$count = 0; | ||
$acceptedDateTimeStamp = new \DateTime(); | ||
|
||
foreach ($datasets as $dataset) { | ||
|
||
$queryString = 'select id, rev, dataset_id, dataset_status, modification_time_stamp | ||
from dataset_submission_audit where dataset_id = :datasetId order by rev desc, id desc'; | ||
$params = [ | ||
'datasetId' => $dataset->getId(), | ||
]; | ||
$params['datasetId'] = $dataset->getId(); | ||
$stmt = $entityManager->getConnection()->prepare($queryString); | ||
$stmt->execute($params); | ||
$auditRevisionFinder = $stmt->fetchAll(); | ||
|
||
$numberOfRevisions = count($auditRevisionFinder); | ||
if ($numberOfRevisions > 1) { | ||
for ($i = ($numberOfRevisions - 1); $i > 0; $i --) { | ||
// The revisions are ordered by latest first. | ||
$oldRevision = $auditRevisionFinder[$i]; | ||
$newRevision = $auditRevisionFinder[($i - 1)]; | ||
|
||
$articleDiff = $this->diff($oldRevision, $newRevision); | ||
|
||
if ($i === ($numberOfRevisions - 1) and $articleDiff['dataset_status']['same'] === Dataset::DATASET_STATUS_ACCEPTED) { | ||
$acceptedDateTimeStamp = $articleDiff['modification_time_stamp']['old']; | ||
} | ||
|
||
if ($articleDiff['dataset_status']['new'] === Dataset::DATASET_STATUS_ACCEPTED) { | ||
if (!empty($articleDiff['modification_time_stamp']['new'])) { | ||
$acceptedDateTimeStamp = $articleDiff['modification_time_stamp']['new']; | ||
} else { | ||
$acceptedDateTimeStamp = $articleDiff['modification_time_stamp']['same']; | ||
} | ||
} | ||
} | ||
} else { | ||
$acceptedDateTimeStamp = $dataset->getModificationTimeStamp(); | ||
} | ||
|
||
$acceptedDateTimeStamp = new \DateTime($acceptedDateTimeStamp); | ||
|
||
if ($acceptedDateTimeStamp instanceof \DateTime) { | ||
|
||
$entityManager->clear(); | ||
$newDataset = $entityManager->getRepository(Dataset::class)->findOneBy(array('id' => $dataset->getId())); | ||
|
||
$newDataset->setAcceptedDate($acceptedDateTimeStamp); | ||
$output->writeln('Accepted date back-filled for dataset: ' . $dataset->getId()); | ||
$entityManager->persist($newDataset); | ||
$entityManager->flush(); | ||
$count++; | ||
} else { | ||
$output->writeln('Modification Time stamp not an instance of DateTime for Dataset Id: ' . $dataset->getId()); | ||
} | ||
$acceptedDateTimeStamp = null; | ||
} | ||
|
||
$output->writeln('Total number of datasets which got back-filled: ' . $count); | ||
} | ||
|
||
/** | ||
* Creates a diff between 2 arrays. | ||
* | ||
* @param array $oldData Array which contains the old data. | ||
* @param array $newData Array which contains the new data. | ||
* | ||
* @return array | ||
*/ | ||
public function diff($oldData, $newData) | ||
{ | ||
$diff = array(); | ||
|
||
$keys = array_keys($oldData + $newData); | ||
foreach ($keys as $field) { | ||
$old = array_key_exists($field, $oldData) ? $oldData[$field] : null; | ||
$new = array_key_exists($field, $newData) ? $newData[$field] : null; | ||
|
||
if ($old == $new) { | ||
$row = array('old' => '', 'new' => '', 'same' => $old); | ||
} else { | ||
$row = array('old' => $old, 'new' => $new, 'same' => ''); | ||
} | ||
|
||
$diff[$field] = $row; | ||
} | ||
|
||
return $diff; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 20 additions & 23 deletions
43
src/Pelagos/Bundle/AppBundle/Resources/views/DatasetSubmission/form.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
<div class="cleair"> | ||
<fieldset> | ||
<p> | ||
<strong>NOTE:</strong> <span style="color:grey">You must have an approved Dataset Information Form (DIF) to fill out and submit a Dataset Submission Form. The red asterisk (<span class="emRequired"/>) is used to indicate required fields. If you need assistance while completing this form, please contact <a href=mailto:griidc@gomri.org>[email protected]</a>.</span> | ||
</p> | ||
<strong>NOTE: | ||
By submitting content to GRIIDC you warrant that you have sufficient rights to make this content available under a <a href="https://creativecommons.org/publicdomain/zero/1.0/" target="_blank">CC0 license</a>. | ||
</strong> | ||
</fieldset> | ||
|
||
<p> <!-- Registry Identifier --> | ||
<fieldset> | ||
<p> | ||
Please enter the Unique Dataset Identifier (UDI) that GRIIDC assigned to your dataset and select "Load Dataset" to load the most recent information for your dataset. | ||
</p> | ||
<form id="regidform"> | ||
<label for="regid"><b>Unique Dataset Identifier (UDI): </b></label> | ||
<input minlength="16" type="text" id="regid" name="regid" size="60" value="{{datasetSubmission.getDatasetSubmissionId|default}}"> | ||
<button disabled | ||
onclick="window.location.href='{{ path('pelagos_app_ui_datasetsubmission_default') }}?regid=' + | ||
document.getElementById('regid').value.trim();" | ||
name="regbutton" id="regbutton" | ||
type="button">Load Dataset</button> | ||
<label class="error" for="regid"></label> | ||
</form> | ||
</fieldset> | ||
<fieldset> | ||
<p> | ||
Please enter the Unique Dataset Identifier (UDI) that GRIIDC assigned to your dataset and select "Load Dataset" to load the most recent information for your dataset. You must have an approved Dataset Information Form (DIF) to fill out and submit a Dataset Submission Form. | ||
</p> | ||
<fieldset> | ||
<b>Approved Dataset Information Forms</b> | ||
{% include "PelagosAppBundle:DatasetSubmission:datasets-approved-difs.html.twig" %} | ||
</fieldset> | ||
<form id="regidform"> | ||
<label for="regid"><b>Unique Dataset Identifier (UDI): </b></label> | ||
<input minlength="16" type="text" id="regid" name="regid" size="60" value="{{datasetSubmission.getDatasetSubmissionId|default}}"> | ||
<button disabled | ||
onclick="window.location.href='{{ path('pelagos_app_ui_datasetsubmission_default') }}?regid=' + | ||
document.getElementById('regid').value.trim();" | ||
name="regbutton" id="regbutton" | ||
type="button">Load Dataset</button> | ||
<label class="error" for="regid"></label> | ||
</form> | ||
<br> | ||
<b>Approved Dataset Information Forms</b> | ||
{% include "PelagosAppBundle:DatasetSubmission:datasets-approved-difs.html.twig" %} | ||
</fieldset> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.