Skip to content

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

4 watching

Forks

Latest commit

 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CGSpace Drupal Importer Module

Requirements

Drupal 10.3 or later in the 10.x series, or Drupal 11, with XMLReader and Country 2.1 or later in the 2.x series. The test environments use PHP 8.3, Drupal 10.6.22 with Drush 12.5.3 and Drupal 11.4.13 with Drush 13.8.1. Country

Release archives omit the development test suite. To run the suite, use a Git checkout of the module and follow the instructions in tests/README.md.

Installation

If you're using composer add ilri/cgspace_importer to your composer.json file under the repositories section.

Example:

{
  "repositories": {
    "ilri/cgspace_importer": {
      "type": "vcs",
      "url": "https://github.com/ilri/dspace-drupal-module.git"
    }
  }
}

If you correctly added the repository as described above you can now run in your shell:

composer require 'ilri/cgspace_importer:^2.0'

If everything has been done correctly, the latest version of the module is downloaded and added to your installation.

You can now enable the module with Drush:

drush en cgspace_importer

or directly from the admin/modules page.

Upgrade from 1.x

On an existing site that meets the requirements above, update the Composer constraint and apply the module's database updates:

composer require 'ilri/cgspace_importer:^2.0'
drush updatedb

The updates install the inventory and report tables and add a lookup index on the standard CGSpace UUID field. Scheduled imports can return exit code 1 after a partial update. See Reports and recovery for the checkpoint and retry behavior.

Configuration

Once the module is installed you need to configure it at the general settings page admin/config/cgspace/settings/general:

  • Endpoint: the CGSpace endpoint Ex: https://dspace7test.ilri.org

  • Importer ID: Your identifier for statistical purposes that will be added at any Request to CGSpace Ex: CGIAR

  • CGSpace discover query Page Size: The CGSpace API Page size for the queries, you can leave it at its default value or tune it depending on your system performance. default: 100

  • Chunk size of nodes to be processed at once: The maximum number of publications processed in one batch step, you can leave it at its default value or tune it depending on your system performance. default: 50

  • DEBUG mode: If checked response times for any CGSpace request are logged. It could be used to measure performance. default: disabled

    Do NOT USE on Production!

If you want to import everything from CGSpace you may skip this step; otherwise, you need to first select the Communities and then the Collections you want to import:

  • Communities: admin/config/cgspace/settings/communities
  • Collections: admin/config/cgspace/settings/collections

Last but not least you need to configure the Processors: admin/config/cgspace/settings/processors where you can decide to use the module embedded vocabularies or map with terms on your existing installation vocabularies.

First run

Run the first import with Drush. Use drush cgspace_importer:create for the selected collections or drush cgspace_importer:create --all to import the publications listed in the CGSpace sitemap. A successful collection-based import clears the pending history for the collections it covered.

Examples

  • Import all CGSpace items on Sitemap Index:

    drush cgspace_importer:create --all
  • Import CGSpace items in Communities and Collections you configured using the CGSpace API:

drush cgspace_importer:create

Large imports

On MySQL and MariaDB, the create, update and delete Drush commands set the parent process's session wait_timeout to at least seven days (604,800 seconds). This keeps its database connection available while it waits for the batch worker. The timeout measures how long that connection can be idle.

Each CGSpace HTTP request has a 120-second limit, including redirects, retries and waits requested by the server. During create and update, a failed Discover page is recorded and the importer reads the remaining pages and collections. If page 1 fails, it tries page 2 once to recover the page count. If both fail, it moves to the next collection. A global create can continue with other sitemap documents. An unavailable item detail is skipped. A failed thumbnail download produces a warning and the publication can still be saved.

Run drush updatedb on existing sites. The module stores inventories, ordered work rows and temporary report entries in dedicated tables. A lookup index on the standard CGSpace UUID field supports processing in blocks. A global create skips existing publications before requesting details. Rerunning it preserves their node IDs.

Reports and recovery

Drush and the cgspace_importer log channel show the run ID, node counts, errors and warnings. Each failure identifies the collection or global scope, the page or item, the endpoint, the cause and the action taken. Errors are logged as they occur. At completion the same details appear together in the final report. Sync CGSpace displays a summary and the run ID for finding the full report in the logs.

Outcome Shell exit code Synchronization checkpoint
Completed, including optional thumbnail warnings 0 Create and update record the UTC start of the run.
Partial update with usable results 1 Advances. The next scheduled update searches for newer changes.
Incomplete create, unusable source, or local processing failure 1 Retains the previous checkpoint.
Incomplete delete inventory or inconclusive absence check 1 Delete leaves the checkpoint alone and removes zero nodes.

For a partial update, use the dated drush cgspace_importer:update YYYY-MM-DD command printed in the report to replay the affected window. A global run includes --all in that command. Newly selected collections with incomplete history stay queued for a full backfill. To recover an incomplete create, rerun the create command printed in its report.

The module releases temporary rows after reporting. After 24 hours of inactivity, cron can reclaim an abandoned inventory in transactions of up to 5,000 work rows with a 10-second budget per pass. Global deletion confirms each missing UUID against Discover before deleting any candidate. A publication with multiple identifiers survives when any one is still present.

Web updates

After the first successful import, open Sync CGSpace at admin/content/cgspace. Since is required and defaults to the UTC date of the saved synchronization checkpoint. Sync updates existing publications on the same node and creates publications first seen in the search results.

Saved selection What Sync does
One or more collections Searches the selected collections from midnight UTC on Since. For each newly selected collection awaiting import, Sync retrieves its full history once.
Communities selected, all their collection lists empty Disables Sync. Select at least one collection in Collections to enable it.
No communities or collections selected Searches all CGSpace publications from Since.

The page displays the scope and uses the selection saved at submission time. Partial web updates use the same checkpoint and recovery rules as Drush.

Drush commands

During inventory collection, Drush displays a progress bar with the current phase underneath. Fetch shows the Discover page or sitemap being requested. Indexing tracks item identifiers stored for the batch. Discover reports progress per collection. Sitemap imports show a running count until the inventory is verified.

For create and update, a second bar counts publications processed, including skipped items. Beneath it, Fetch shows cumulative time spent on CGSpace HTTP requests, including inventory pages, item details, thumbnail downloads and retries. Processing shows the remaining time spent in the inventory and publication batch steps, including indexing and saving nodes. Both timers use hours, minutes and seconds. Redirected output and --no-ansi use periodic text updates. Use --quiet to suppress progress.

This module provides the following Drush commands:

  • cgspace_importer:create [--all]

    Create Publication nodes by generating the list through the CGSpace API according to communities and collections selected on the configuration page.

    • --all

      if --all option is specified the list of Publication nodes is generated from CGSpace sitemap index

  • cgspace_importer:update [YYYY-MM-DD] [--all]

    Update or create Publication nodes by generating the list through the CGSpace API according to communities and collections selected on the configuration page.

    If a date argument is specified, the list of updated or added items is generated accordingly

    • --all

      if --all option is specified the list of Publication nodes is generated through CGSpace API without taking care of collections and communities selected on the configuration page.

  • cgspace_importer:delete [--all]

    Delete Publication nodes comparing with the list of items generated through the CGSpace API according to communities and collections selected on the configuration page.

    • --all

      if --all option is specified the Publication nodes are compared to the list of items generated from the CGSpace sitemap index.

  • cgspace_importer:purge [--dry-run] (alias cgspace-purge) cleans up temporary import data. Use delete to reconcile publication nodes with CGSpace.

Clean up interrupted imports

Preview all remaining inventories, their Drupal batch IDs, last activity and eligibility times in UTC, work rows, queued operations and estimated logical size.

ddev drush cgspace_importer:purge --dry-run

An inventory becomes eligible 24 hours after its last heartbeat. An import can run for several days while it keeps reporting activity. The preview totals include only eligible inventories. The command verifies ownership before counting a Drupal batch and its queue, including for older inventories where the batch ID was never saved. A batch ID marked linked only records an association whose exclusive ownership could not be verified.

ddev drush cgspace_importer:purge

The command finishes the inventories eligible at startup in transactions of up to 5,000 work rows. It rechecks activity before claiming each inventory. Cron uses the same cleanup with a 10-second budget per pass. After an interruption, either can continue from the last committed block. Mixed batches and their queues are preserved.

A run that removed one inventory could report the following totals.

Metric           Removed
Drupal batches   1
Inventories      1
Work rows        10000
Queue jobs       2
Logical payload  1.05 MiB (1101000 bytes)

Logical payload counts the bytes in the inventory rows’ four identifier fields, the run IDs and messages of temporary report entries, and the serialized data of removed batches and queue jobs. The database can reuse allocated pages, so its files may retain their size after cleanup. An empty purge succeeds with zero totals.

Examples

  • Import all CGSpace publications starting from CGSpace Sitemap Index

    drush cgspace_importer:create --all
  • Import all CGSpace publications starting from configured Communities and Collections

    drush cgspace_importer:create
  • Search all CGSpace for publications added or modified since the saved checkpoint

    drush cgspace_importer:update --all
  • Update publications nodes using CGSpace API according to configured Communities and Collections.

    drush cgspace_importer:update
  • Update from a specific date (Ex: January, 1st 2020)

    drush cgspace_importer:update 2020-01-01

    Tip: if you use a very old date as an argument, the behavior is similar to running create. Use carefully!

  • Remove Publication nodes using CGSpace API according to configured Communities and Collections.

    drush cgspace_importer:delete

    Tip: if you don't select any collections in the configuration this command removes all published nodes of the configured publication type that carry a CGSpace UUID.

  • Remove published imports whose absence from CGSpace is confirmed against the global sitemap and Discover.

    drush cgspace_importer:delete --all

Cron jobs and update

Schedule drush cgspace_importer:update for the selected collections or drush cgspace_importer:update --all for all CGSpace publications. For a manual update, use Sync CGSpace.

IMPORTANT: we suggest to run the update functionality:

  • once per day in the case of full import with --all option
  • once per week in case of partial import with configured Communities and Collections

Since we have some limitations from the current CGSpace API we're able to get added/updated items from the drush cgspace_importer:update command but not the removed ones. This means that you need to run periodically the delete drush cgspace_importer:delete command as well.

IMPORTANT: we suggest to run the delete functionality:

  • once per day in the case of full import with --all option
  • once per week in case of partial import with configured Communities and Collections

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages