From b1ef3dc49a5f155a3342cb8b1dc25436d038b68e Mon Sep 17 00:00:00 2001 From: Nicolas Brassard Date: Mon, 8 Apr 2013 09:15:57 -0400 Subject: [PATCH 01/11] Prepare the 1.3 release --- LICENCE.txt | 2 +- README.md | 12 ++++++++---- extension.driver.php | 14 ++++++++++---- extension.meta.xml | 8 ++++++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/LICENCE.txt b/LICENCE.txt index 3dbe37d..d6116ad 100644 --- a/LICENCE.txt +++ b/LICENCE.txt @@ -5,7 +5,7 @@ follows: ----- begin license block ----- Copyright 2011 Solutions Nitriques -Copyright 2012 Deux Huit Huit +Copyright 2012-2013 Deux Huit Huit Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 21c811e..3a609d0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Duplicate Sections # -Version: 1.2 +Version: 1.3 ## Easily duplicate/clone your section parameters and fields ## @@ -16,11 +16,15 @@ For user with symphony CMS version 2.2.x, use tag V1.1 ### INSTALLATION ### -- Unzip the duplicate_section.zip file -- (re)Name the folder ***duplicate_section*** +- `git clone` / download and unpack the tarball file +- (re)Name the folder **duplicate_section** - Put into the extension directory - Enable/install just like any other extension +See + *Voila !* -http://www.nitriques.com/open-source/ +### CREDITS ### + +Come say hi! -> diff --git a/extension.driver.php b/extension.driver.php index aa155e3..18d38de 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -1,6 +1,7 @@ 0) { - // get the fields of the section $fields = $section->fetchFields(); // if we have some if (is_array($fields)) { - + // copy each field foreach ($fields as &$field) { @@ -166,7 +166,10 @@ public function __action(Array &$context) { $f->commit(); } } - + + // get this section relations + + // redirect to the new cloned section redirect(sprintf( '%s/blueprints/sections/edit/%s/', @@ -176,6 +179,9 @@ public function __action(Array &$context) { // stop everything now exit; + + } else { + throw new Exception("Could not create a new section"); } } } diff --git a/extension.meta.xml b/extension.meta.xml index a592c20..47afc17 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -11,11 +11,11 @@ - Solutions Nitriques + Solutions Nitriques http://www.nitriques.com - Deux Huit Huit + Deux Huit Huit http://www.deuxhuithuit.com @@ -27,6 +27,10 @@ + + - Fix some bugs with Duplicate Section + - Added cloning the relationships + - Update for compatibility with symphony 2.3 From 0b4e5bf9eaa29e5788ed7166c380646f07431462 Mon Sep 17 00:00:00 2001 From: Nicolas Brassard Date: Mon, 8 Apr 2013 11:38:12 -0400 Subject: [PATCH 02/11] Working on relations --- extension.driver.php | 56 ++++++++++++++++++++++++++++++++++++++++---- extension.meta.xml | 8 +++---- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 18d38de..6ec556c 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -103,7 +103,23 @@ private static function getChildrenWithClass($rootElement, $tagName, $className) } return NULL; } - + + /** + * This method search to the field referenced by the $handle param + * and returns its id. + * + * @param array $fields + * @param string $handle + */ + private static function getNewFieldId(Array &$fields, $handle) { + foreach ($fields as &$field) { + var_dump($field->get()); + if ($field->get('element_name') == $handle) { + return intval($field->get('id')); + } + } + return NULL; + } /** * @@ -111,7 +127,7 @@ private static function getChildrenWithClass($rootElement, $tagName, $className) * @param array $context */ public function __action(Array &$context) { - + // append button self::appendElementBelowView($context); // if the clone button was hit @@ -120,11 +136,13 @@ public function __action(Array &$context) { $section_id = $c['context'][1]; + // original section $section = SectionManager::fetch($section_id); if ($section != null) { + // get its settings $section_settings = $section->get(); - + // remove id unset($section_settings['id']); @@ -136,7 +154,7 @@ public function __action(Array &$context) { $new_section_id = SectionManager::add($section_settings); // if the create new section was successful - if ( is_numeric($new_section_id) && $new_section_id > 0) { + if (is_numeric($new_section_id) && $new_section_id > 0) { // get the fields of the section $fields = $section->fetchFields(); @@ -168,7 +186,33 @@ public function __action(Array &$context) { } // get this section relations + $relationships = SectionManager::fetchAssociatedSections($section_id, false); + // fetch the new fields + $new_section = SectionManager::fetch($new_section_id); + $new_fields = $new_section->fetchFields(); + + if (is_array($relationships)) { + // re-create all of those relations + foreach ($relationships as $relation) { + var_dump($relation);die; + + $new_section_field_id = self::getNewFieldId($new_fields, $relation['handle']); + + if (is_numeric($new_section_field_id) && $new_section_field_id > 0) { + SectionManager::createSectionAssociation( + $new_section_id, // the new parent + $relation['child_field_id'], + $new_section_field_id, // the new parent field + $relation['show_association'] + ); + var_dump($child_field_id); + } else { + throw new Exception(sprintf("Could not find the '%s' field", $relation['handle'])); + } + } + } + die; // redirect to the new cloned section redirect(sprintf( @@ -183,7 +227,9 @@ public function __action(Array &$context) { } else { throw new Exception("Could not create a new section"); } + } else { + Throw new Exception("Section not found"); } - } + } // end clonde button } } \ No newline at end of file diff --git a/extension.meta.xml b/extension.meta.xml index 47afc17..ddaf953 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -10,14 +10,14 @@ Sections - - Solutions Nitriques - http://www.nitriques.com - Deux Huit Huit http://www.deuxhuithuit.com + + Solutions Nitriques + http://www.nitriques.com + Pascal Piche http://www.nitriques.com From fe9db91d6bc13663487560bbe7f3c82a2fe5ebc3 Mon Sep 17 00:00:00 2001 From: Nicolas Brassard Date: Mon, 8 Apr 2013 22:03:41 -0400 Subject: [PATCH 03/11] Relations ships looks like cloned too... --- extension.driver.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 6ec556c..fa05344 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -186,7 +186,7 @@ public function __action(Array &$context) { } // get this section relations - $relationships = SectionManager::fetchAssociatedSections($section_id, false); + /*$relationships = SectionManager::fetchAssociatedSections($section_id, false); // fetch the new fields $new_section = SectionManager::fetch($new_section_id); @@ -201,9 +201,9 @@ public function __action(Array &$context) { if (is_numeric($new_section_field_id) && $new_section_field_id > 0) { SectionManager::createSectionAssociation( - $new_section_id, // the new parent - $relation['child_field_id'], - $new_section_field_id, // the new parent field + $new_section_id, // the new parent (cloned section) + $relation['child_field_id'], // the section on which the cloned section is linked to + $new_section_field_id, // the new parent field (cloned secyion) $relation['show_association'] ); var_dump($child_field_id); @@ -212,7 +212,7 @@ public function __action(Array &$context) { } } } - die; + die;*/ // redirect to the new cloned section redirect(sprintf( From 53afab0db1db79c011d1c63e30d749821c1e9a59 Mon Sep 17 00:00:00 2001 From: Nicolas Brassard Date: Mon, 8 Apr 2013 22:05:00 -0400 Subject: [PATCH 04/11] Relations ships looks like cloned too... --- extension.meta.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index ddaf953..d4440c5 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -29,7 +29,6 @@ - Fix some bugs with Duplicate Section - - Added cloning the relationships - Update for compatibility with symphony 2.3 From 86bec7f71094ff48fcb19052f2bb5bda2dd0432f Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 27 Apr 2017 10:15:17 -0400 Subject: [PATCH 05/11] Update for Symphony 4.x Update of release version. Wrap CloneInput in svg-icon-container to fit with Symphony 4.x layout. cc @nitriques --- extension.driver.php | 119 +++++++++++++++++++++++-------------------- extension.meta.xml | 5 +- 2 files changed, 67 insertions(+), 57 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index fa05344..fbfa6d0 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -31,9 +31,9 @@ public function getSubscribedDelegates(){ ) ); } - + /** - * + * * Fired on each backend page, detect when it's time to append elements into the backend page * @param array $context */ @@ -41,42 +41,49 @@ public function appendElementBelowView(Array &$context) { // only if logged in // this prevents the clone button from appearing on the login screen if (Administration::instance()->isLoggedIn()) { - + $c = Administration::instance()->getPageCallback(); - + // when editing a section if ($c['driver'] == 'blueprintssections' && $c['context'][0] == 'edit') { - + $form = Administration::instance()->Page->Form; - + $button_wrap = new XMLELement('div', NULL, array( 'id' => 'duplicate-section' )); - - $btn = new XMLElement('button', __('Clone'), array( - 'id' => 'duplicate-section-clone', - 'class' => 'button', - 'name' => 'action[clone]', - 'type' => 'submit', - 'title' => __('Duplicate this section'), - 'style' => 'margin-left: 10px; background: #81B934', - 'onclick' => "jQuery('fieldset.settings').empty();return true;" - )); - - $button_wrap->appendChild($btn); - + + $btn = new XMLElement( + 'button', __('Clone'), + array( + 'id' => 'duplicate-section-clone', + 'class' => 'button', + 'name' => 'action[clone]', + 'type' => 'submit', + 'title' => __('Duplicate this section'), + 'style' => 'margin-left: 10px; background: #81B934', + 'onclick' => "jQuery('fieldset.settings').empty();return true;" + ) + ); + + $button_wrap = Widget::SVGIconContainer( + 'clone', + $btn, + array('id' => 'duplicate-section') + ); + // add content to the right div $div_action = self::getChildrenWithClass($form, 'div', 'actions'); - + if ($div_action != NULL) { - $div_action->appendChild($button_wrap); + $div_action->insertChildAt(1, $button_wrap); } } } } - + /** - * + * * Recursive search for an Element with the right name and css class. * Stops at fists match * @param XMLElement $rootElement @@ -87,23 +94,23 @@ private static function getChildrenWithClass($rootElement, $tagName, $className) if (! ($rootElement) instanceof XMLElement) { return NULL; // not and XMLElement } - + // contains the right css class and the right node name if (strpos($rootElement->getAttribute('class'), $className) > -1 && $rootElement->getName() == $tagName) { return $rootElement; } - + // recursive search in child elements foreach ($rootElement->getChildren() as $child) { $res = self::getChildrenWithClass($child, $tagName, $className); - + if ($res != NULL) { return $res; } } return NULL; } - + /** * This method search to the field referenced by the $handle param * and returns its id. @@ -120,85 +127,85 @@ private static function getNewFieldId(Array &$fields, $handle) { } return NULL; } - + /** - * + * * Delegate AdminPagePreGenerate that handles the click of the 'clone' button and append the button in the form * @param array $context */ - public function __action(Array &$context) { + public function __action(Array &$context) { // append button self::appendElementBelowView($context); - + // if the clone button was hit if (is_array($_POST['action']) && isset($_POST['action']['clone'])) { $c = Administration::instance()->getPageCallback(); - + $section_id = $c['context'][1]; - + // original section $section = SectionManager::fetch($section_id); - + if ($section != null) { // get its settings $section_settings = $section->get(); - + // remove id unset($section_settings['id']); - + // new name $section_settings['name'] .= ' ' . time(); $section_settings['handle'] = Lang::createHandle($section_settings['name']); - + // save it $new_section_id = SectionManager::add($section_settings); - + // if the create new section was successful if (is_numeric($new_section_id) && $new_section_id > 0) { - + // get the fields of the section $fields = $section->fetchFields(); - + // if we have some if (is_array($fields)) { - + // copy each field foreach ($fields as &$field) { - + // get field settings $fs = $field->get(); - + // un set the current id unset($fs['id']); - + // set the new section as the parent $fs['parent_section'] = $new_section_id; - + // create the new field $f = FieldManager::create($fs['type']); - + // set its settings $f->setArray($fs); - + // save $f->commit(); } } - + // get this section relations /*$relationships = SectionManager::fetchAssociatedSections($section_id, false); - + // fetch the new fields $new_section = SectionManager::fetch($new_section_id); $new_fields = $new_section->fetchFields(); - + if (is_array($relationships)) { // re-create all of those relations foreach ($relationships as $relation) { var_dump($relation);die; - + $new_section_field_id = self::getNewFieldId($new_fields, $relation['handle']); - + if (is_numeric($new_section_field_id) && $new_section_field_id > 0) { SectionManager::createSectionAssociation( $new_section_id, // the new parent (cloned section) @@ -213,17 +220,17 @@ public function __action(Array &$context) { } } die;*/ - + // redirect to the new cloned section redirect(sprintf( '%s/blueprints/sections/edit/%s/', SYMPHONY_URL, $new_section_id )); - + // stop everything now exit; - + } else { throw new Exception("Could not create a new section"); } @@ -232,4 +239,4 @@ public function __action(Array &$context) { } } // end clonde button } - } \ No newline at end of file + } diff --git a/extension.meta.xml b/extension.meta.xml index d4440c5..4bdbd3d 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -27,6 +27,9 @@ + + - Update for Symphony 4.x + - Fix some bugs with Duplicate Section @@ -38,4 +41,4 @@ - \ No newline at end of file + From fe396718cb974585e1e5a4c1d7142223dcc768db Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 27 Apr 2017 13:10:24 -0400 Subject: [PATCH 06/11] Update release date --- extension.meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index 4bdbd3d..d9b38ac 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -27,7 +27,7 @@ - + - Update for Symphony 4.x From 4c942c4cf4e4dce8c403a69c05fee909abb9d171 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 5 May 2017 15:05:37 -0400 Subject: [PATCH 07/11] Add extension custom icon to core Widget::SVGIcon. --- extension.driver.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extension.driver.php b/extension.driver.php index fbfa6d0..46940ad 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -53,8 +53,14 @@ public function appendElementBelowView(Array &$context) { 'id' => 'duplicate-section' )); + Widget::registerSVGIcon( + 'clone', + '' + ); + $btn = new XMLElement( - 'button', __('Clone'), + 'button', + __('Clone'), array( 'id' => 'duplicate-section-clone', 'class' => 'button', From ebb1638713dffe26e127ece4c78d5b0c26deb310 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 17 May 2017 10:56:58 -0400 Subject: [PATCH 08/11] Update php-min/php-max info --- extension.meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index d9b38ac..99517e7 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -27,7 +27,7 @@ - + - Update for Symphony 4.x From f4a0ef47fbe647196f95a746e00ee9b9f3fe9f3f Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 24 Aug 2017 15:36:11 -0400 Subject: [PATCH 09/11] SQL and PHP cases PHP true,false,null in lowercase SQL keywords uppercase --- extension.driver.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 46940ad..48d6590 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -49,7 +49,7 @@ public function appendElementBelowView(Array &$context) { $form = Administration::instance()->Page->Form; - $button_wrap = new XMLELement('div', NULL, array( + $button_wrap = new XMLELement('div', null, array( 'id' => 'duplicate-section' )); @@ -81,7 +81,7 @@ public function appendElementBelowView(Array &$context) { // add content to the right div $div_action = self::getChildrenWithClass($form, 'div', 'actions'); - if ($div_action != NULL) { + if ($div_action != null) { $div_action->insertChildAt(1, $button_wrap); } } @@ -98,7 +98,7 @@ public function appendElementBelowView(Array &$context) { */ private static function getChildrenWithClass($rootElement, $tagName, $className) { if (! ($rootElement) instanceof XMLElement) { - return NULL; // not and XMLElement + return null; // not and XMLElement } // contains the right css class and the right node name @@ -110,11 +110,11 @@ private static function getChildrenWithClass($rootElement, $tagName, $className) foreach ($rootElement->getChildren() as $child) { $res = self::getChildrenWithClass($child, $tagName, $className); - if ($res != NULL) { + if ($res != null) { return $res; } } - return NULL; + return null; } /** @@ -131,7 +131,7 @@ private static function getNewFieldId(Array &$fields, $handle) { return intval($field->get('id')); } } - return NULL; + return null; } /** From 892a15993fb55924fd9d7569ce1b73120bdf927b Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 19 Jun 2018 11:11:36 -0400 Subject: [PATCH 10/11] Replace deprecated method fetch() by select() --- extension.driver.php | 12 ++++++++++-- extension.meta.xml | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 48d6590..259db75 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -150,7 +150,11 @@ public function __action(Array &$context) { $section_id = $c['context'][1]; // original section - $section = SectionManager::fetch($section_id); + $section = (new SectionManager) + ->select() + ->section($section_id) + ->execute() + ->next(); if ($section != null) { // get its settings @@ -202,7 +206,11 @@ public function __action(Array &$context) { /*$relationships = SectionManager::fetchAssociatedSections($section_id, false); // fetch the new fields - $new_section = SectionManager::fetch($new_section_id); + $new_section = (new SectionManager) + ->select() + ->section($new_section_id) + ->execute() + ->next(); $new_fields = $new_section->fetchFields(); if (is_array($relationships)) { diff --git a/extension.meta.xml b/extension.meta.xml index 99517e7..a0ea45e 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -29,6 +29,7 @@ - Update for Symphony 4.x + - Replace deprecated method fetch() by select() - Fix some bugs with Duplicate Section From a7a39e0a51f56300b409203c47952c1a1caa9ed6 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 28 Jun 2018 09:14:05 -0400 Subject: [PATCH 11/11] Fix for right context values --- extension.driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 259db75..5f1499b 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -45,7 +45,7 @@ public function appendElementBelowView(Array &$context) { $c = Administration::instance()->getPageCallback(); // when editing a section - if ($c['driver'] == 'blueprintssections' && $c['context'][0] == 'edit') { + if ($c['driver'] == 'blueprintssections' && $c['context']['action'] == 'edit') { $form = Administration::instance()->Page->Form; @@ -147,7 +147,7 @@ public function __action(Array &$context) { if (is_array($_POST['action']) && isset($_POST['action']['clone'])) { $c = Administration::instance()->getPageCallback(); - $section_id = $c['context'][1]; + $section_id = $c['context']['id']; // original section $section = (new SectionManager)