Jump to content

Bug: Pages Database Template Rename Issue.


TDBF
Go to solution Solved by Stuart Silvester,

Recommended Posts

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.

  1. Create a Pages Database Template:
  2. Go to Themes ACP and click on the Designer Mode button,
  3. Enable Designers' Mode and Click Next and wait until all templates are exported to disk,
  4. Now disable Designers Mode and Synchronize the changes leaving the files on server,
  5. 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.
  6. Enable Designers' Mode and Click Next and wait until all templates are exported to disk,
  7. 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,
  8. Now disable Designers Mode and Synchronize the changes leaving the files on server,
  9. 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.

  1. 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.
  2. 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. 😋

Link to comment
Share on other sites

  • 2 months later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...