Enables resource duplication via save.

 - Adds a duplicate action button.
 - Duplicates a resource, persists it, and redirects the user to edit
   the newly duplicated resource.

 No return.
192982
def enable_resource_duplication_via_save
      action_item(*compatible_action_item_parameters) do
        if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
          link_to(I18n.t(:duplicate_model, default: "Duplicate %{model}", scope: [:active_admin], model: active_admin_config.resource_label), action: :duplicate)
        end
      end

      member_action :duplicate do
        resource  = resource_class.find(params[:id])

        authorize! ActiveAdmin::Auth::CREATE, resource

        duplicate = resource.amoeba_dup
        if duplicate.save
          redirect_to({ action: :edit, id: duplicate.id }, flash: { notice: "#{active_admin_config.resource_label} was successfully duplicated." })
        else
          redirect_to({ action: :show }, flash: { error: "#{active_admin_config.resource_label} could not be duplicated." })
        end
      end
    end
1193183
def duplicate
      enhance_settings
      p = self.dup
      p.category = 'COPY OF ' + category
      p.created_at = p.updated_at = nil
      p.url = url
      p.attachment = attachment

      # allow site to do some customization
      p.send(:duplicate_extra, self) if p.respond_to?(:duplicate_extra)
      p.save!
      p
    end
1329809
def links_duplicate_on(attribute, separator)
      links.map do  |link|
        link.send(attribute).split(separator).collect do |value|
          link.dup.update(Hash[attribute, value])
        end
      end.flatten
    end
568911
def duplicate(self, contributor=None):
        
        bundle = [
            {'original': data, 'copy': data.duplicate(contributor=contributor)}
            for data in self
        ]

        bundle = rewire_inputs(bundle)
        duplicated = [item['copy'] for item in bundle]

        return duplicated
704446
public function refresh()
    {
        // Several refresh() calls might happen during one request. If that is the case, the Resource Manager can't know
        // that the first created resource object doesn't have to be persisted / published anymore. Thus we need to
        // delete the resource manually in order to avoid orphaned resource objects:
        if ($this->resource !== null) {
            $this->resourceManager->deleteResource($this->resource);
        }

        parent::refresh();
        $this->renderResource();
    }
108623
def edit_resource_path(*args)
      options = args.extract_options!
      options.merge! :action => :edit

      super_path(with_nesting(args.first || resource), options)
    end
212736
public function duplicateAction()
    {
        $id = $this->getRequest()->get($this->admin->getIdParameter());
        $object = $this->admin->getObject($id);
        $new = clone $object;

        $this->duplicateFiles($object, $new);

        $preResponse = $this->preDuplicate($new);
        if ($preResponse !== null) {
            return $preResponse;
        }

        return $this->createAction($new);
    }
337940
function dedupe(resources, onDupe) {
  // first create a map of name->[array of resources with same name]
  var names = {};
  resources.forEach(function(scriptResource) {
    if (names[scriptResource.name] == null) {
      names[scriptResource.name] = [];
    }
    names[scriptResource.name].push(scriptResource);
  });

  // Call the de-dupe function for each set of dupes
  Object.keys(names).forEach(function(name) {
    var clones = names[name];
    if (clones.length > 1) {
      onDupe(clones);
    }
  });
}
925245
function Resource(url, params, actions, options$$1) {

    var self = this || {}, resource = {};

    actions = assign({},
        Resource.actions,
        actions
    );

    each(actions, function (action, name) {

        action = merge({url: url, params: assign({}, params)}, options$$1, action);

        resource[name] = function () {
            return (self.$http || Http)(opts(action, arguments));
        };
    });

    return resource;
}
1001468
public function duplicateAction()
    {
        $id     = $this->getRequest()->get($this->admin->getIdParameter());
        $object = $this->admin->getObject($id);

        if (!$object) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }

        if (false === $this->admin->isGranted('DUPLICATE', $object)) {
            throw new AccessDeniedException();
        }

        $newObject = clone $object;

        if (method_exists($newObject, 'setTitle')) {
            $newObject->setTitle('[COPY] - ' . $newObject->getTitle());
        }

        $objectManager = $this->getDoctrine()->getManager();
        $objectManager->persist($newObject);
        $objectManager->flush();

        $this->addFlash(
            'sonata_flash_success',
            $this->admin->trans('flash_duplicate_success')
        );

        return new RedirectResponse($this->admin->generateObjectUrl('edit', $newObject));
    }
901697
function it_retains_the_original_state_of_the_instance_duplicated_with_new_scheme()
    {
        $original_uri = (string) $this->getWrappedObject();

        $new_scheme = $this->withScheme("http");

        $this->__toString()->shouldReturn($original_uri);
    }
861625
def save_resource(self, resource_form, *args, **kwargs):
        """"""
        # Implemented from kitosid template for -
        # osid.resource.ResourceAdminSession.update_resource
        if resource_form.is_for_update():
            return self.update_resource(resource_form, *args, **kwargs)
        else:
            return self.create_resource(resource_form, *args, **kwargs)
16300
def save_self(execute_hooks = true)
      # short-circuit if the resource is not dirty
      return saved? unless dirty_self?

      if execute_hooks
        new? ? create_with_hooks : update_with_hooks
      else
        _persist
      end
      clean?
    end
816780
def duplicate(self, contributor=None, inherit_collections=False):
        """"""
        duplicate = Entity.objects.get(id=self.id)
        duplicate.pk = None
        duplicate.slug = None
        duplicate.name = 'Copy of {}'.format(self.name)
        duplicate.duplicated = now()
        if contributor:
            duplicate.contributor = contributor

        duplicate.save(force_insert=True)

        assign_contributor_permissions(duplicate)

        # Override fields that are automatically set on create.
        duplicate.created = self.created
        duplicate.save()

        # Duplicate entity's data objects.
        data = get_objects_for_user(contributor, 'view_data', self.data.all())  # pylint: disable=no-member
        duplicated_data = data.duplicate(contributor)
        duplicate.data.add(*duplicated_data)

        if inherit_collections:
            collections = get_objects_for_user(
                contributor,
                'add_collection',
                self.collections.all()  # pylint: disable=no-member
            )
            for collection in collections:
                collection.entity_set.add(duplicate)
                copy_permissions(collection, duplicate)
                collection.data.add(*duplicated_data)
                for datum in duplicated_data:
                    copy_permissions(collection, datum)

        return duplicate
1105747
@Override
    public void actionExit() throws IOException, JspException, ServletException {

        if (getAction() == ACTION_CANCEL) {
            // save and exit was canceled
            return;
        }

        // unlock resource, if no modified
        actionClear(false);

        // close the editor
        actionClose();
    }
593803
def persist!(saved = false)
      @new_record, @uri = false
      if changed?
        @previous_changes = changes if saved
        changed_attributes.clear
      end
      true
    end
911832
def duplicate(self, contributor=None):
        """"""
        if self.status not in [self.STATUS_DONE, self.STATUS_ERROR]:
            raise ValidationError('Data object must have done or error status to be duplicated')

        duplicate = Data.objects.get(id=self.id)
        duplicate.pk = None
        duplicate.slug = None
        duplicate.name = 'Copy of {}'.format(self.name)
        duplicate.duplicated = now()
        if contributor:
            duplicate.contributor = contributor

        duplicate._perform_save(force_insert=True)  # pylint: disable=protected-access

        assign_contributor_permissions(duplicate)

        # Override fields that are automatically set on create.
        duplicate.created = self.created
        duplicate._perform_save()  # pylint: disable=protected-access

        if self.location:
            self.location.data.add(duplicate)  # pylint: disable=no-member

        duplicate.storages.set(self.storages.all())  # pylint: disable=no-member

        for migration in self.migration_history.order_by('created'):  # pylint: disable=no-member
            migration.pk = None
            migration.data = duplicate
            migration.save(force_insert=True)

        # Inherit existing child dependencies.
        DataDependency.objects.bulk_create([
            DataDependency(child=duplicate, parent=dependency.parent, kind=dependency.kind)
            for dependency in DataDependency.objects.filter(child=self)
        ])
        # Inherit existing parent dependencies.
        DataDependency.objects.bulk_create([
            DataDependency(child=dependency.child, parent=duplicate, kind=dependency.kind)
            for dependency in DataDependency.objects.filter(parent=self)
        ])

        return duplicate