diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index c90ac39d9d5b1d72b8e7e814f089d4613a46718f..a4fb642671b22b832ed4f1f3dca7aa20cad2308f 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -300,10 +300,16 @@ $config = array( ), 'db_table' => array( 'abstract_factories' => array('VuFind\Db\Table\PluginFactory'), + 'factories' => array( + 'resource' => function ($sm) { + return new \VuFind\Db\Table\Resource( + $sm->getServiceLocator()->get('VuFind\DateConverter') + ); + }, + ), 'invokables' => array( 'changetracker' => 'VuFind\Db\Table\ChangeTracker', 'comments' => 'VuFind\Db\Table\Comments', - 'resource' => 'VuFind\Db\Table\Resource', 'resourcetags' => 'VuFind\Db\Table\ResourceTags', 'search' => 'VuFind\Db\Table\Search', 'session' => 'VuFind\Db\Table\Session', diff --git a/module/VuFind/src/VuFind/Controller/UpgradeController.php b/module/VuFind/src/VuFind/Controller/UpgradeController.php index 053dd5cad6b16958053ab85ff21406dfd10b100b..b959bb02ed2c3468d757eb0dbfcbd665e4731b2d 100644 --- a/module/VuFind/src/VuFind/Controller/UpgradeController.php +++ b/module/VuFind/src/VuFind/Controller/UpgradeController.php @@ -470,11 +470,12 @@ class UpgradeController extends AbstractBase // Process submit button: if (strlen($this->params()->fromPost('submit', '')) > 0) { + $converter = $this->getServiceLocator()->get('VuFind\DateConverter'); foreach ($problems as $problem) { try { $driver = $this->getRecordLoader() ->load($problem->record_id, $problem->source); - $problem->assignMetadata($driver)->save(); + $problem->assignMetadata($driver, $converter)->save(); } catch (RecordMissingException $e) { $this->session->warnings->append( "Unable to load metadata for record " diff --git a/module/VuFind/src/VuFind/Db/Row/Resource.php b/module/VuFind/src/VuFind/Db/Row/Resource.php index 111fbd9cecafc449a925066c998f13d6c6ad5356..ef708085ba5ba82e32cd54539882714a6ac94a7c 100644 --- a/module/VuFind/src/VuFind/Db/Row/Resource.php +++ b/module/VuFind/src/VuFind/Db/Row/Resource.php @@ -121,11 +121,12 @@ class Resource extends ServiceLocatorAwareGateway * Use a record driver to assign metadata to the current row. Return the * current object to allow fluent interface. * - * @param \VuFind\RecordDriver\AbstractBase $driver The record driver. + * @param \VuFind\RecordDriver\AbstractBase $driver The record driver + * @param \VuFind\Date\Converter $converter Date converter * * @return \VuFind\Db\Row\Resource */ - public function assignMetadata($driver) + public function assignMetadata($driver, \VuFind\Date\Converter $converter) { // Grab title -- we have to have something in this field! $this->title = $driver->tryMethod('getSortTitle'); @@ -142,7 +143,6 @@ class Resource extends ServiceLocatorAwareGateway // Try to find a year; if not available, just leave the default null: $dates = $driver->tryMethod('getPublicationDates'); if (isset($dates[0]) && strlen($dates[0]) > 4) { - $converter = new DateConverter(); try { $year = $converter->convertFromDisplayDate('Y', $dates[0]); } catch (DateException $e) { diff --git a/module/VuFind/src/VuFind/Db/Table/Resource.php b/module/VuFind/src/VuFind/Db/Table/Resource.php index aca1f03a9c7966550dc1f786ec65f74043b7d38e..cb48373a95b10d3846314602c46bc80cb406fcf0 100644 --- a/module/VuFind/src/VuFind/Db/Table/Resource.php +++ b/module/VuFind/src/VuFind/Db/Table/Resource.php @@ -39,11 +39,21 @@ use Zend\Db\Sql\Expression; */ class Resource extends Gateway { + /** + * Date converter + * + * @var \VuFind\Date\Converter + */ + protected $dateConverter; + /** * Constructor + * + * @param \VuFind\Date\Converter $converter Date converter */ - public function __construct() + public function __construct(\VuFind\Date\Converter $converter) { + $this->dateConverter = $converter; parent::__construct('resource', 'VuFind\Db\Row\Resource'); } @@ -84,7 +94,7 @@ class Resource extends Gateway } // Load metadata into the database for sorting/failback purposes: - $result->assignMetadata($driver); + $result->assignMetadata($driver, $this->dateConverter); // Save the new row. $result->save();