{"id":13684405,"url":"https://github.com/riesenia/cakephp-duplicatable","last_synced_at":"2026-01-11T16:51:09.605Z","repository":{"id":52179295,"uuid":"45679037","full_name":"riesenia/cakephp-duplicatable","owner":"riesenia","description":"CakePHP plugin for duplicating entities including related data","archived":false,"fork":false,"pushed_at":"2024-08-07T14:25:47.000Z","size":127,"stargazers_count":52,"open_issues_count":5,"forks_count":19,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-12T05:37:22.738Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/riesenia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-06T11:47:14.000Z","updated_at":"2024-11-04T11:13:33.000Z","dependencies_parsed_at":"2024-11-12T05:32:18.019Z","dependency_job_id":"27ff281e-eb3a-4890-827b-f0b752c8edaa","html_url":"https://github.com/riesenia/cakephp-duplicatable","commit_stats":{"total_commits":90,"total_committers":15,"mean_commits":6.0,"dds":"0.43333333333333335","last_synced_commit":"c3e68b811334f336e373edb0bb52040665d1794a"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riesenia%2Fcakephp-duplicatable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riesenia%2Fcakephp-duplicatable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riesenia%2Fcakephp-duplicatable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riesenia%2Fcakephp-duplicatable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/riesenia","download_url":"https://codeload.github.com/riesenia/cakephp-duplicatable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251777779,"owners_count":21642224,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T14:00:33.162Z","updated_at":"2026-01-11T16:51:09.561Z","avatar_url":"https://github.com/riesenia.png","language":"PHP","funding_links":[],"categories":["ORM / Database / Datamapping","Plugins"],"sub_categories":["ORM / Database / Datamapping"],"readme":"# Duplicatable behavior for CakePHP\n\n[![CI](https://github.com/riesenia/cakephp-duplicatable/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/riesenia/cakephp-duplicatable/actions/workflows/ci.yml)\n[![Coverage Status](https://img.shields.io/codecov/c/github/riesenia/cakephp-duplicatable.svg?style=flat-square)](https://codecov.io/github/riesenia/cakephp-duplicatable)\n[![Latest Version](https://img.shields.io/packagist/v/riesenia/cakephp-duplicatable.svg?style=flat-square)](https://packagist.org/packages/riesenia/cakephp-duplicatable)\n[![Total Downloads](https://img.shields.io/packagist/dt/riesenia/cakephp-duplicatable.svg?style=flat-square)](https://packagist.org/packages/riesenia/cakephp-duplicatable)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n\nThis plugin contains a behavior that handles duplicating entities including related data.\n\n## Installation\n\nUsing composer\n\n```\ncomposer require riesenia/cakephp-duplicatable\n```\n\nLoad plugin using\n\n```sh\nbin/cake plugin load Duplicatable\n```\n\n## Usage\n\nThis behavior provides multiple methods for your `Table` objects.\n\n### Method `duplicate`\n\nThis behavior provides a `duplicate` method for the table. It takes the primary key of the record to duplicate as its only argument.\nUsing this method will clone the record defined by the primary key provided as well as all related records as defined in the configuration.\n\n### Method `duplicateEntity`\n\nThis behavior provides a `duplicateEntity` method for the table. It mainly acts as the `duplicate` method except it does not save the duplicated record but returns the Entity to be saved instead. This is useful if you need to manipulate the Entity before saving it.\n\n## Configuration options:\n\n* *finder* - finder to use to get entities. Set it to \"translations\" to fetch and duplicate translations, too. Defaults to \"all\". It is possible to set an array for more finders.\n* *contain* - set related entities that will be duplicated\n* *remove* - fields that will be removed from the entity\n* *set* - fields that will be set to provide value or callable to modify the value. If you provide a callable, it will take the entity being cloned as the only argument\n* *prepend* - fields that will have value prepended by the provided text\n* *append* - fields that will have value appended by provided text\n* *saveOptions* - options for save on primary table\n* *preserveJoinData* - if `_joinData` property in `BelongsToMany` relations should be preserved - defaults to `false` due to tricky nature of this association\n\n## Examples\n\n```php\nclass InvoicesTable extends Table\n{\n    public function initialize(array $config): void\n    {\n        parent::initialize($config);\n\n        // add Duplicatable behavior\n        $this-\u003eaddBehavior('Duplicatable.Duplicatable', [\n            // table finder\n            'finder' =\u003e 'all',\n            // duplicate also items and their properties\n            'contain' =\u003e ['InvoiceItems.InvoiceItemProperties'],\n            // remove created field from both invoice and items\n            'remove' =\u003e ['created', 'invoice_items.created'],\n            // mark invoice as copied\n            'set' =\u003e [\n                'name' =\u003e function($entity) {\n                    return md5($entity-\u003ename) . ' ' . $entity-\u003ename;\n                },\n                'copied' =\u003e true\n            ],\n            // prepend properties name\n            'prepend' =\u003e ['invoice_items.invoice_items_properties.name' =\u003e 'NEW '],\n            // append copy to the name\n            'append' =\u003e ['name' =\u003e ' - copy']\n        ]);\n\n        // associations (InvoiceItems table hasMany InvoiceItemProperties)\n        $this-\u003ehasMany('InvoiceItems', [\n            'foreignKey' =\u003e 'invoice_id',\n            'className' =\u003e 'InvoiceItems'\n        ]);\n    }\n}\n\n// ... somewhere in the controller\n$this-\u003eInvoices-\u003eduplicate(4);\n```\n\nSometimes you need to access the original entity, e.g. for setting an ancestor/parent id reference.\nIn this case you can leverage the `$original` entity being passed in as 2nd argument:\n```php\n'set' =\u003e [\n    'ancestor_id' =\u003e function ($entity, $original) {\n        return $original-\u003eid;\n    },\n],\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friesenia%2Fcakephp-duplicatable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Friesenia%2Fcakephp-duplicatable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friesenia%2Fcakephp-duplicatable/lists"}