Giter Club home page Giter Club logo

copyresources's Introduction

Copy Resources

An Omeka S module for copying resources, including items, item sets, sites, and site pages.

For Module Developers

Events

This module provides events where other modules may do something after copies have been made.

  • copy_resources.*.pre: Do something before copying a resource. Replace * with the resource name. Intended to allow modules to modify the JSON-LD before the resource has been copied. Params:
    • copy_resources: The CopyResources service object
    • resource: The original resource
    • json_ld: The JSON-LD used to copy the resource. Modules may modify the JSON-LD and send it back using $event->setParam('json_ld', $jsonLd)
  • copy_resources.*.post: Do something after copying a resource. Replace * with the resource name. Intended to allow modules to copy their data after the resource has been copied. Params:
    • copy_resources: The CopyResources service object
    • resource: The original resource
    • resource_copy: The item set copy

Copying Sites

Copying sites is more involved than copying other resources because modules may add data to sites that must also be copied. These modules will need to listen to the copy_resources.sites.post event and make adjustments so their data is correctly copied over.

Modules that add block layouts and navigation links to sites via the block_layouts and navigation_links configuration will need to revert the copied layouts and links to their original state. Thankfully, the CopyResources service object has convenience methods for this. For example:

$sharedEventManager->attach(
    '*',
    'copy_resources.sites.post',
    function (Event $event) {
        $copyResources = $event->getParam('copy_resources');
        $siteCopy = $event->getParam('resource_copy');

        // Revert block layout and link types.
        $copyResources->revertSiteBlockLayouts($siteCopy->id(), 'my_block_layout');
        $copyResources->revertSiteNavigationLinkTypes($siteCopy->id(), 'my_link_type');
    }
);

Modules that add API resources that are assigned to sites will need to copy the resources and assign them to the new site. Again, the CopyResources service object has convenience methods for this. For example:

$sharedEventManager->attach(
    '*',
    'copy_resources.sites.post',
    function (Event $event) {
        $api = $this->getServiceLocator()->get('Omeka\ApiManager');
        $site = $event->getParam('resource');
        $siteCopy = $event->getParam('resource_copy');
        $copyResources = $event->getParam('copy_resources');

        // Create resource copies.
        $myApiResources = $api->search('my_api_resource', ['site_id' => $site->id()])->getContent();
        foreach ($myApiResources as $myApiResource) {
            $preCallback = function (&$jsonLd) use ($siteCopy){
                unset($jsonLd['o:owner']);
                $jsonLd['o:site']['o:id'] = $siteCopy->id();
            };
            $copyResources->createResourceCopy('my_api_resource', $myApiResource, $preCallback);
        }
    }
);

Modules may need to modify block layout data and navigation link data to update for the site copy. Again, the CopyResources service object has convenience methods for this. For example:

$sharedEventManager->attach(
    '*',
    'copy_resources.sites.post',
    function (Event $event) {
        $copyResources = $event->getParam('copy_resources');
        $siteCopy = $event->getParam('resource_copy');

        // Modify block data.
        $callback = function (&$data) {
            $data['foo'] = 'bar';
        };
        $copyResources->modifySiteBlockData($siteCopy->id(), 'my_block_layout', $callback);

        // Modify site navigation.
        $callback = function (&$link) use ($visualizationmMap) {
            $data['baz'] = 'bat';
        };
        $copyResources->modifySiteNavigation($siteCopy->id(), 'my_link_type', $callback);

    }
);

Copyright

Copy Resources is Copyright © 2021-present Corporation for Digital Scholarship, Vienna, Virginia, USA http://digitalscholar.org

The Corporation for Digital Scholarship distributes the Omeka source code under the GNU General Public License, version 3 (GPLv3). The full text of this license is given in the license file.

The Omeka name is a registered trademark of the Corporation for Digital Scholarship.

Third-party copyright in this distribution is noted where applicable.

All rights not expressly granted are reserved.

copyresources's People

Contributors

jimsafley avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

copyresources's Issues

List of pages block

The "list of pages" block doesn't seem to be copying (and may be the source of my bug?).

It appears to have the same content copied on the editing side:
Screenshot 2024-06-17 at 13 39 02

But on public:
Screenshot 2024-06-17 at 13 38 03

(The original, for reference:)
Screenshot 2024-06-17 at 13 37 59

Testing: Copy Resources module

The Copy Resources module allows users to copy selected resources, including items, item sets, sites, and site pages. There are two places a user can copy a resource: 1) from the browse page using the "Copy" icon; and 2) from the resource page using the "Copy" button. Clicking on the icon and button opens up a sidebar where the user confirms the copy. Once the module copies the resource, it automatically navigates to the new resource's page, where the user can make adjustments as needed.

To test this module, copy several items, item sets, sites, and site pages. Check that data does indeed duplicate as expected. Users should be able copy resources that they have permission to create. Copied resources should be owned by the user who copied the resource, not the original owner.

Note that copying an item will not copy its media. If a user must copy an item's media, they can use the Omeka S Item Importer module, which already has the ability to copy items along with their media.

Also note that when copying a site, navigation links and page blocks added by modules may carry over as invalid placeholders (stubs). Users will have to replace them or reorganize their navigation and pages. Other data added by modules may not carry over at all.

Even so, modules do have the opportunity to revert their blocks/links and copy their data during the process. Below are the modules that add links, blocks, and/or data to sites:

Module Link(s) Block(s) Data
Collecting X forms
Datavis X X visualizations
FacetedBrowse X pages
ItemCarouselBlock X
Mapping X X
Scripto X X

Currently, each of these modules have a "copy-resources" branch that should copy their data over. Test that this is the case.

Testing: Set visibility on copy

Per this discussion, the set-visibility-on-copy branch adds a way for users to set visibility when copying a resource. Every copy sidebar should now include a "Visibility" select with the following options:

  • Same as original: the copied resource will be the same visibility as the original (default)
  • Public: the copied resource will be public
  • Private: the copied resource will be private

Make sure this all behaves as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.