Skip to content

Commit

Permalink
NBBIB-497 Add dynamic query to cron() reference year sync
Browse files Browse the repository at this point in the history
  • Loading branch information
camilocodes committed Jan 24, 2025
1 parent 63b748b commit 418dbf2
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions custom/modules/nbbib_core/nbbib_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,31 @@ function nbbib_core_cron() {
$current_minute = date('i');
$datestamp = date('c');

// if (TRUE) { // CRON DEV - RUN EVERY TIME!
if (TRUE) { // CRON DEV - RUN EVERY TIME!
// If it's between 12:45-1am server time...
if ($current_hour < 1 and $current_minute > 44) {
//if ($current_hour < 1 and $current_minute > 44) {
\Drupal::logger('nbbib_core')->notice("NBBIB maintenance CRON job started at [$datestamp].");
// Publication year config sync.
// Load reference types from configuration.
$config = \Drupal::config('nbbib_core.settings');
$types = $config->get('nbbib_types');
$types = array_column($types, 'entity');
$refs = '';
$i = 1;

\Drupal::logger('nbbib_core')->notice("Starting publication year facet sync...");
$query = \Drupal::database()->query(
'SELECT MIN(publication_year) AS db_min
FROM (
SELECT publication_year FROM yabrm_book t1 WHERE publication_year > 0 AND status = 1
UNION
SELECT publication_year FROM yabrm_journal_article t2 WHERE publication_year > 0 AND status = 1
UNION
SELECT publication_year FROM yabrm_book_section t3 WHERE publication_year > 0 AND status = 1
UNION
SELECT publication_year FROM yabrm_thesis t4 WHERE publication_year > 0 AND status = 1
) AS t5'
);
foreach($types as $type) {
$refs .= "
SELECT publication_year FROM $type t$i
WHERE publication_year > 0
AND status = 1
UNION";
$i++;
}

$refs = substr($refs, 0, -5);
$qtext = "SELECT MIN(publication_year) AS db_min \nFROM ($refs) AS t$i";
$query = \Drupal::database()->query($qtext);
$db_min = $query->fetchAll()[0]->db_min;
$dt_max = date('Y');
// Check/configure new edge values for facet.
Expand Down

0 comments on commit 418dbf2

Please # to comment.