diff --git a/config/vufind/config.ini b/config/vufind/config.ini index 5935eff66151a9afcb7f86e13a9e68e9efbb054b..c10551d886d18cbb3fcb00cc1dc2a8608d8936b1 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -1001,26 +1001,31 @@ era = true ; allow browsing of era subdivisions ; <result_limit> most popular entries -- it only affects display order. ;alphabetical_order = true -; This section controls which record export methods are displayed on the Record -; view screen. Note that some options may be disabled for records that do not -; support them, regardless of the setting chosen here. You can edit the separate -; export.ini file to add new export formats and change the behavior of existing ones. +; This section controls the availability of export methods. +; +; Each entry may be a comma-separated list of contexts in which the export +; option will be presented. Valid options: +; +; bulk - Included in batch export contexts +; record - Included in single-record export contexts +; +; If you simply set a field to true, only "record" mode will be enabled. +; If you set a field to false, all export contexts will be disabled. +; +; Note that some options may be disabled for records that do not support them, +; regardless of the setting chosen here. You can edit the separate export.ini +; file to add new export formats and change the behavior of existing ones. [Export] -RefWorks = true -EndNote = true -EndNoteWeb = true +RefWorks = "record,bulk" +EndNote = "record,bulk" +EndNoteWeb = "record,bulk" MARC = false MARCXML = false RDF = false BibTeX = false RIS = false -; This section controls whether or not display the bulk export options and which -; options to display. Valid methods are EndNote and MARC - The method must also -; be enabled in Export (above) or it will not be displayed. [BulkExport] -enabled = true -options = MARC:MARCXML:EndNote:EndNoteWeb:RefWorks:BibTeX:RIS ; Export behavior to use when no bulkExportType setting is found in the matching ; format section of export.ini; default is 'link' if not overridden below. See ; export.ini for more details on available options. diff --git a/module/VuFind/src/VuFind/Config/Upgrade.php b/module/VuFind/src/VuFind/Config/Upgrade.php index 32be637994f3373a5bb10fe4e81fb12d4fb04223..5788b549e29584c0bcc592256a26a468f8c9d76c 100644 --- a/module/VuFind/src/VuFind/Config/Upgrade.php +++ b/module/VuFind/src/VuFind/Config/Upgrade.php @@ -525,11 +525,19 @@ class Upgrade // Set up reference for convenience (and shorter lines): $newConfig = & $this->newConfigs['config.ini']; - // If the [BulkExport] options setting is an old default, update it to - // reflect the fact that we now support more options. - if ($this->isDefaultBulkExportOptions($newConfig['BulkExport']['options'])) { - $newConfig['BulkExport']['options'] - = 'MARC:MARCXML:EndNote:EndNoteWeb:RefWorks:BibTeX:RIS'; + // If the [BulkExport] options setting is present and non-default, warn + // the user about its deprecation. + if (isset($newConfig['BulkExport']['options'])) { + $default = $this->isDefaultBulkExportOptions( + $newConfig['BulkExport']['options'] + ); + if (!$default) { + $this->addWarning( + 'The [BulkExport] options setting is deprecated; please ' + . 'customize the [Export] section instead.' + ); + } + unset($newConfig['BulkExport']['options']); } // Warn the user about Amazon configuration issues: diff --git a/module/VuFind/src/VuFind/Export.php b/module/VuFind/src/VuFind/Export.php index 8e073e67b48b89829b9ad6246e313bcac39c03cc..ac91cb8ccb5d3c64b43cfc3d2653e3d14ab9c363 100644 --- a/module/VuFind/src/VuFind/Export.php +++ b/module/VuFind/src/VuFind/Export.php @@ -54,11 +54,12 @@ class Export protected $exportConfig; /** - * Bulk options (initialized to boolean false, populated later) + * Property to cache active formats + * (initialized to empty array , populated later) * - * @var array|bool + * @var array */ - protected $bulkOptions = false; + protected $activeFormats = []; /** * Constructor @@ -75,28 +76,13 @@ class Export /** * Get bulk export options. * + * @deprecated use getActiveFormats($context) instead + * * @return array */ public function getBulkOptions() { - if ($this->bulkOptions === false) { - $this->bulkOptions = []; - if (isset($this->mainConfig->BulkExport->enabled) - && isset($this->mainConfig->BulkExport->options) - && $this->mainConfig->BulkExport->enabled - ) { - $config = explode(':', $this->mainConfig->BulkExport->options); - foreach ($config as $option) { - if (isset($this->mainConfig->Export->$option) - && $this->mainConfig->Export->$option == true - ) { - $this->bulkOptions[] = $option; - } - } - } - } - - return $this->bulkOptions; + return $this->getActiveFormats('bulk'); } /** @@ -271,14 +257,12 @@ class Export { // Get an array of enabled export formats (from config, or use defaults // if nothing in config array). - $active = isset($this->mainConfig->Export) - ? $this->mainConfig->Export->toArray() - : ['RefWorks' => true, 'EndNote' => true]; + $active = $this->getActiveFormats('record'); // Loop through all possible formats: $formats = []; foreach (array_keys($this->exportConfig->toArray()) as $format) { - if (isset($active[$format]) && $active[$format] + if (in_array($format, $active) && $this->recordSupportsFormat($driver, $format) ) { $formats[] = $format; @@ -299,7 +283,7 @@ class Export */ public function getFormatsForRecords($drivers) { - $formats = $this->getBulkOptions(); + $formats = $this->getActiveFormats('bulk'); foreach ($drivers as $driver) { // Filter out unsupported export formats: $newFormats = []; @@ -358,4 +342,46 @@ class Export ? $this->mainConfig->BulkExport->defaultType : 'link'; } + /** + * Get active export formats for the given context. + * + * @param string $context Export context (i.e. record, bulk) + * + * @return array + */ + public function getActiveFormats($context = 'record') + { + if (!isset($this->activeFormats[$context])) { + $formatSettings = isset($this->mainConfig->Export) + ? $this->mainConfig->Export->toArray() + : ['RefWorks' => 'record,bulk', 'EndNote' => 'record,bulk']; + + $active = []; + foreach ($formatSettings as $format => $allowedContexts) { + if (strpos($allowedContexts, $context) !== false + || ($context == 'record' && $allowedContexts == 1) + ) { + $active[] = $format; + } + } + + // for legacy settings [BulkExport] + if ($context == 'bulk' + && isset($this->mainConfig->BulkExport->enabled) + && $this->mainConfig->BulkExport->enabled + && isset($this->mainConfig->BulkExport->options) + ) { + $config = explode(':', $this->mainConfig->BulkExport->options); + foreach ($config as $option) { + if (isset($this->mainConfig->Export->$option) + && $this->mainConfig->Export->$option == true + ) { + $active[] = $option; + } + } + } + $this->activeFormats[$context] = array_unique($active); + } + return $this->activeFormats[$context]; + } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Config/UpgradeTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Config/UpgradeTest.php index a7f1ac5490c4356d145c5f613479d9daa730b2dd..6c2b4fa2398c7de1c95c157f07dbafc79ef35620 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Config/UpgradeTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Config/UpgradeTest.php @@ -74,13 +74,6 @@ class UpgradeTest extends \VuFindTest\Unit\TestCase $upgrader->run(); $results = $upgrader->getNewConfigs(); - // We should always update BulkExport options to latest full set when - // upgrading a default configuration: - $this->assertEquals( - 'MARC:MARCXML:EndNote:EndNoteWeb:RefWorks:BibTeX:RIS', - $results['config.ini']['BulkExport']['options'] - ); - // Prior to 1.4, Advanced should always == HomePage after upgrade: if ((float)$version < 1.4) { $this->assertEquals( diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ExportTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ExportTest.php index 7f4d6da4e73d966aa6752289852579d957eb63f5..a727f90546e148ac5b15941f36cdbae00971939c 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/ExportTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ExportTest.php @@ -40,11 +40,11 @@ use VuFind\Export, Zend\Config\Config; class ExportTest extends \PHPUnit_Framework_TestCase { /** - * Test bulk options. + * Test bulk options using legacy (deprecated) configuration. * * @return void */ - public function testGetBulkOptions() + public function testGetBulkOptionsLegacy() { $config = [ 'BulkExport' => [ @@ -62,6 +62,47 @@ class ExportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['foo', 'bar'], $export->getBulkOptions()); } + /** + * Test bulk options. + * + * @return void + */ + public function testGetBulkOptions() + { + $config = [ + 'Export' => [ + 'foo' => 'record,bulk', + 'bar' => 'record,bulk', + 'baz' => 0, + 'xyzzy' => 'record', + ], + ]; + $export = $this->getExport($config); + $this->assertEquals(['foo', 'bar'], $export->getBulkOptions()); + } + + /** + * Test active formats. + * + * @return void + */ + public function testGetActiveFormats() + { + $config = [ + 'Export' => [ + 'foo' => 'record,bulk', + 'bar' => 'record,bulk', + 'baz' => 0, + 'xyzzy' => 1, + ], + ]; + $export = $this->getExport($config); + $this->assertEquals(['foo', 'bar'], $export->getActiveFormats('bulk')); + $this->assertEquals( + ['foo', 'bar', 'xyzzy'], $export->getActiveFormats('record') + ); + } + /** * Test "needs redirect" * @@ -173,13 +214,9 @@ class ExportTest extends \PHPUnit_Framework_TestCase public function testGetFormatsForRecords() { $mainConfig = [ - 'BulkExport' => [ - 'enabled' => 1, - 'options' => 'anything:marc', - ], 'Export' => [ - 'anything' => 1, - 'marc' => 1, + 'anything' => 'record,bulk', + 'marc' => 'record,bulk', ], ]; $exportConfig = [ diff --git a/themes/bootstrap3/templates/cart/cart.phtml b/themes/bootstrap3/templates/cart/cart.phtml index 316749c140f14d6964a3230b11ae6a4d32d433ed..271a063cab1790f0eda8fc2f788eb9f06f2633ae 100644 --- a/themes/bootstrap3/templates/cart/cart.phtml +++ b/themes/bootstrap3/templates/cart/cart.phtml @@ -8,7 +8,7 @@ ?> <?=$this->flashmessages()?> <form class="form-inline" action="<?=$this->url('cart-home')?>" method="post" name="cartForm"> - <? if (!$this->cart()->isEmpty()): ?> + <? if (!$this->cart()->isEmpty()): ?> <div class="cart-controls clearfix"> <div class="checkbox pull-left flip"> <label> @@ -26,7 +26,7 @@ <i class="fa fa-envelope-o"></i> <?=$this->transEsc('Email')?> </button> - <? $exportOptions = $this->export()->getBulkOptions(); if (count($exportOptions) > 0): ?> + <? $exportOptions = $this->export()->getActiveFormats('bulk'); if (count($exportOptions) > 0): ?> <button type="submit" class="btn btn-default" name="export" title="<?=$this->transEsc('bookbag_export')?>" value="1"> <i class="fa fa-list-alt"></i> <?=$this->transEsc('Export')?> @@ -55,7 +55,7 @@ <li><a id="cart-confirm-empty" onClick="submitCartForm(this, {'empty':'empty'})" title="<?=$this->transEsc('bookbag_confirm_empty')?>"><?=$this->transEsc('confirm_dialog_yes')?></a></li> <li><a onClick="$('.fa.fa-spinner').remove()"><?=$this->transEsc('confirm_dialog_no')?></a></li> </ul> - </div> + </div> </div> <? endif; ?> <?=$this->render('cart/contents.phtml')?> diff --git a/themes/bootstrap3/templates/myresearch/bulk-action-buttons.phtml b/themes/bootstrap3/templates/myresearch/bulk-action-buttons.phtml index 84ccef33ef781a6f438b32a6208679a3791722cd..ae475661b8e4cb3a382a93ce1868c790882e825b 100644 --- a/themes/bootstrap3/templates/myresearch/bulk-action-buttons.phtml +++ b/themes/bootstrap3/templates/myresearch/bulk-action-buttons.phtml @@ -14,7 +14,7 @@ <? if ((!is_null($this->list) && $this->list->editAllowed($user)) || is_null($this->list) && $user): ?> <input class="btn btn-default" id="<?=$this->idPrefix?>delete_list_items_<?=!is_null($this->list) ? $this->escapeHtmlAttr($this->list->id) : ''?>" type="submit" name="delete" value="<?=$this->transEsc('Delete')?>" title="<?=$this->transEsc('delete_selected')?>"/> <? endif; ?> - <? $exportOptions = $this->export()->getBulkOptions(); if (count($exportOptions) > 0): ?> + <? $exportOptions = $this->export()->getActiveFormats('bulk'); if (count($exportOptions) > 0): ?> <input class="btn btn-default" type="submit" name="export" value="<?=$this->transEsc('Export')?>" title="<?=$this->transEsc('export_selected')?>"/> <? endif; ?> <input class="btn btn-default" type="submit" name="print" value="<?=$this->transEsc('Print')?>" title="<?=$this->transEsc('print_selected')?>"/> diff --git a/themes/bootstrap3/templates/search/bulk-action-buttons.phtml b/themes/bootstrap3/templates/search/bulk-action-buttons.phtml index 11e524940949556fd7240c782b8723a314d80ec1..63b39371ce55d37e624c3ca2a13266a9153ec4de 100644 --- a/themes/bootstrap3/templates/search/bulk-action-buttons.phtml +++ b/themes/bootstrap3/templates/search/bulk-action-buttons.phtml @@ -10,7 +10,7 @@ <div class="btn-group"> <? if (isset($this->showBulkOptions) && $this->showBulkOptions): ?> <input id="ribbon-email" class="btn btn-default modal-link" type="submit" name="email" title="<?=$this->transEsc('bookbag_email_selected')?>" value="<?=$this->transEsc('Email')?>"/> - <? $exportOptions = $this->export()->getBulkOptions(); if (count($exportOptions) > 0): ?> + <? $exportOptions = $this->export()->getActiveFormats('bulk'); if (count($exportOptions) > 0): ?> <input id="ribbon-export" class="btn btn-default modal-link" type="submit" name="export" title="<?=$this->transEsc('bookbag_export_selected')?>" value="<?=$this->transEsc('Export')?>"/> <? endif; ?> <input id="ribbon-print" class="btn btn-default modal-link" type="submit" name="print" title="<?=$this->transEsc('bookbag_print_selected')?>" value="<?=$this->transEsc('Print')?>"/>