Skip to content

Commit

Permalink
Add default values for instructor/course/department when none matched…
Browse files Browse the repository at this point in the history
… in reserve data; increase test coverage of index reserves command
  • Loading branch information
meganschanz committed Oct 21, 2024
1 parent 2208601 commit 684249d
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 17 deletions.
3 changes: 3 additions & 0 deletions languages/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,11 @@ No Preference = "No Preference"
No reviews were found for this record = "No reviews were found for this record"
No saved logins = "No saved logins"
No Tags = "No Tags"
no_course_listed = "No Course Listed"
no_department_listed = "No Department Listed"
no_description = "Description not available."
no_email_address = "Email address missing."
no_instructor_listed = "No Instructor Listed"
no_items_selected = "No Items were Selected"
no_proxied_user = "No proxied user (request for yourself)"
nohit_active_filters = "One or more facet filters have been applied to this search. If you remove filters, you may retrieve more results."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use VuFind\I18n\Translator\TranslatorAwareInterface;
use VuFind\Reserves\CsvReader;
use VuFindSearch\Backend\Solr\Document\UpdateDocument;
use VuFindSearch\Backend\Solr\Record\SerializableRecord;
Expand All @@ -54,8 +55,10 @@
name: 'util/index_reserves',
description: 'Course reserves index builder'
)]
class IndexReservesCommand extends AbstractSolrAndIlsCommand
class IndexReservesCommand extends AbstractSolrAndIlsCommand implements TranslatorAwareInterface
{
use \VuFind\I18n\Translator\TranslatorAwareTrait;

/**
* Default delimiter for reading files
*
Expand Down Expand Up @@ -154,11 +157,11 @@ protected function buildReservesIndex(
'id' => $id,
'bib_id' => [],
'instructor_id' => $instructorId,
'instructor' => $instructors[$instructorId] ?? '',
'instructor' => $instructors[$instructorId] ?? $this->translate('no_instructor_listed'),
'course_id' => $courseId,
'course' => $courses[$courseId] ?? '',
'course' => $courses[$courseId] ?? $this->translate('no_course_listed'),
'department_id' => $departmentId,
'department' => $departments[$departmentId] ?? '',
'department' => $departments[$departmentId] ?? $this->translate('no_department_listed'),
];
}
if (!in_array($record['BIB_ID'], $index[$id]['bib_id'])) {
Expand Down Expand Up @@ -194,6 +197,19 @@ protected function getCsvReader(
return new CsvReader($files, $delimiter, $template);
}

/**
* Print the message to the provided output stream prefixed with a timestamp.
*
* @param OutputInterface $output Output object
* @param string $message Message to display
*
* @return null
*/
protected function writeln(OutputInterface $output, string $message)
{
$output->writeln(date('Y-m-d H:i:s') . ' ' . $message);
}

/**
* Run the command.
*
Expand All @@ -204,6 +220,8 @@ protected function getCsvReader(
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->writeln($output, 'Starting reserves processing');
$startTime = date('Y-m-d H:i:s');
// Check time limit; increase if necessary:
if (ini_get('max_execution_time') < 3600) {
ini_set('max_execution_time', '3600');
Expand All @@ -215,29 +233,45 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($file = $input->getOption('filename')) {
try {
$reader = $this->getCsvReader($file, $delimiter, $template);
$this->writeln($output, 'Retrieving instructors');
$instructors = $reader->getInstructors();
$this->writeln($output, 'Found instructor count: ' . count($instructors));
$this->writeln($output, 'Retrieving courses');
$courses = $reader->getCourses();
$this->writeln($output, 'Found course count: ' . count($courses));
$this->writeln($output, 'Retrieving departments');
$departments = $reader->getDepartments();
$this->writeln($output, 'Found department count: ' . count($departments));
$this->writeln($output, 'Retrieving reserves');
$reserves = $reader->getReserves();
$this->writeln($output, 'Found reserve count: ' . count($reserves));
} catch (\Exception $e) {
$output->writeln($e->getMessage());
$this->writeln($output, $e->getMessage());
return 1;
}
} elseif ($delimiter !== $this->defaultDelimiter) {
$output->writeln('-d (delimiter) is meaningless without -f (filename)');
$this->writeln($output, '-d (delimiter) is meaningless without -f (filename)');
return 1;
} elseif ($template !== $this->defaultTemplate) {
$output->writeln('-t (template) is meaningless without -f (filename)');
$this->writeln($output, '-t (template) is meaningless without -f (filename)');
return 1;
} else {
try {
// Connect to ILS and load data:
$this->writeln($output, 'Retrieving instructors');
$instructors = $this->catalog->getInstructors();
$this->writeln($output, 'Found instructor count: ' . count($instructors ?? []));
$this->writeln($output, 'Retrieving courses');
$courses = $this->catalog->getCourses();
$this->writeln($output, 'Found course count: ' . count($courses ?? []));
$this->writeln($output, 'Retrieving departments');
$departments = $this->catalog->getDepartments();
$this->writeln($output, 'Found department count: ' . count($departments ?? []));
$this->writeln($output, 'Retrieving reserves');
$reserves = $this->catalog->findReserves('', '', '');
$this->writeln($output, 'Found reserve count: ' . count($reserves ?? []));
} catch (\Exception $e) {
$output->writeln($e->getMessage());
$this->writeln($output, $e->getMessage());
return 1;
}
}
Expand All @@ -249,22 +283,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
&& !empty($reserves)
) {
// Delete existing records
$this->writeln($output, 'Clearing existing reserves');
$this->solr->deleteAll('SolrReserves');

// Build and Save the index
$this->writeln($output, 'Building new reserves index');
$index = $this->buildReservesIndex(
$instructors,
$courses,
$departments,
$reserves
);
$this->writeln($output, 'Writing new reserves index');
$this->solr->save('SolrReserves', $index);

// Commit and Optimize the Solr Index
$this->solr->commit('SolrReserves');
$this->solr->optimize('SolrReserves');

$output->writeln('Successfully loaded ' . count($reserves) . ' rows.');
$this->writeln($output, 'Successfully loaded ' . count($reserves) . ' rows.');
$endTime = date('Y-m-d H:i:s');
$this->writeln($output, ' Stated at: ' . $startTime . ' Completed at: ' . $endTime);
return 0;
}
$missing = array_merge(
Expand All @@ -273,7 +312,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
empty($departments) ? ['departments'] : [],
empty($reserves) ? ['reserves'] : []
);
$output->writeln(
$this->writeln(
$output,
'Unable to load data. No data found for: ' . implode(', ', $missing)
);
return 1;
Expand Down
Loading

0 comments on commit 684249d

Please sign in to comment.