TDBF Posted February 22, 2022 Posted February 22, 2022 This issue is both an annoyance and a bug, one affects the other imo. Application: CMD/Pages Bug: Renaming a template can cause duplicate of a Database template when it's imported via Themes Designer Mode or when creating another the Database Template with the same name. Not only does this bug break your own naming guidelines, but it can cause duplicates of the same database template which will lead to issues when deleting one of the duplicates within Database Templates window. How to reproduce. Create a Pages Database Template: Go to Themes ACP and click on the Designer Mode button, Enable Designers' Mode and Click Next and wait until all templates are exported to disk, Now disable Designers Mode and Synchronize the changes leaving the files on server, Return to the Pages Templates window and edit the Database Template previously created, do not edit the name, but just save the template name as is. Enable Designers' Mode and Click Next and wait until all templates are exported to disk, Go to the server where your IPB install is and navigate to /themes/cms/database directory and rename the Database Template you created previously so that it is all lower case, Now disable Designers Mode and Synchronize the changes leaving the files on server, There should now be two version of the Database template that you created. If you remove one of them, both will be deleted. Solution. The reason for this happening is two fold. When you originally create a database template, there are limitations places of the Database Template Name which are: Please use only a-z and 0-9 without any special characters or spaces. The title must start with a letter or underscore. When you edit a Database Template, the name will be displayed differently, it will be title case and without any underscores and I can save with spaces regardless of the limitations in place: Please use only a-z and 0-9 without any special characters or spaces. The group name must start with a letter or underscore. You can use an underscore, which will show as a space when viewing templates. The issue lies within the function databaseTemplateGroupOptions() (file: cms/modules/admin/pages/templates.php Line: 1004 😞 form->add( new \IPS\Helpers\Form\Text( 'cms_database_group_name', \IPS\cms\Templates::readableGroupName( \IPS\Request::i()->group ), NULL, array( 'regex' => '/^([A-Z_][A-Z0-9_\.\s]+?)$/i' ), function( $val ) Issues Group Name Change: \IPS\cms\Templates::readableGroupName( \IPS\Request::i()->group ) Is the first issue. This changes the group variable from 'my_template_name' to 'My Template Name'. On line 1026: This line here: $new = str_replace( ' ', '_', $values['cms_database_group_name'] ); Should be changed to $new = str_replace( ' ', '_', mb_strtolower($values['cms_database_group_name'])); As you can see from this part of the function, $new is not set to be lower case as it should be which when saving the field to the database and this can cause conflicts with importing later. if ( $values = $form->values() ) { $new = str_replace( ' ', '_', $values['cms_database_group_name'] ); if ( $new != \IPS\Request::i()->group ) { \IPS\Db::i()->update( 'cms_templates', array( 'template_group' => $new ), array( 'template_location=? and template_group=?', 'database', \IPS\Request::i()->group ) ); foreach( \IPS\cms\Templates::$databaseDefaults as $field => $template ) { \IPS\Db::i()->update( 'cms_databases', array( 'database_template_' . $field => mb_strtolower( $new ) ), array( 'database_template_' . $field . ' =?', \IPS\Request::i()->group ) ); } unset( \IPS\Data\Store::i()->cms_databases ); $this->findAndUpdateTemplates( $new, \IPS\Request::i()->group ); } \IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=templates' . ( isset( \IPS\Request::i()->t_location ) ? '&t_location=' . \IPS\Request::i()->t_location : '' ) ), 'saved' ); } Sorry for the long-winded approach to this issue. 😋 Sonya* 1
TDBF Posted February 22, 2022 Author Posted February 22, 2022 Create Database Template: Edit Database Template: After Exporting CMS templates to disk: Field name's when saved to database table. Well, there's about an hour I won't get back 🤣 Hopefully this will be a bit helpful. SeNioR- 1
Sonya* Posted February 22, 2022 Posted February 22, 2022 I can confirm it. I've caught the bug with duplicate template too, deleting one and then loosing both. TDBF and SeNioR- 1 1
Solution Stuart Silvester Posted May 17, 2022 Solution Posted May 17, 2022 Thank you for your report, I have committed a potential fix for this issue that should be included in a future release. SeNioR- and TDBF 1 1
Recommended Posts