Doctrine 1
  1. Doctrine 1
  2. DC-623

Impossible to create non-unique slugs

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.2
    • Fix Version/s: None
    • Component/s: Sluggable
    • Labels:
      None

      Description

      I want to create a non-unique slug of a title field from my table.

      But I've found that when I change unique from 'true' to 'false' the slugs were not created or updated

      In lib\Doctrine\Template\Listener\Sluggable.php inside preUpdate() function the first if() statement disables the unique (false) option.

        Activity

        Adwise Internetmarketing created issue -
        Hide
        Jacob Mather added a comment -

        Theoretically this should clear up the issue. Sorry for not having the time for a complete test at the moment,

        Show
        Jacob Mather added a comment - Theoretically this should clear up the issue. Sorry for not having the time for a complete test at the moment,
        Jacob Mather made changes -
        Field Original Value New Value
        Attachment dc-623.patch [ 10750 ]
        webPragmatist made changes -
        Comment [ I'm not sure what the point of the check for unique is on preUpdate. Maybe this function is incomplete?

        {code}
            /**
             * Set the slug value automatically when a record is updated if the options are configured
             * to allow it
             *
             * @param Doctrine_Event $event
             * @return void
             */
            public function preUpdate(Doctrine_Event $event)
            {
                if (false !== $this->_options['unique']) {
                    $record = $event->getInvoker();
                    $name = $record->getTable()->getFieldName($this->_options['name']);

                    if ( ! $record->$name || (
                        false !== $this->_options['canUpdate'] &&
                        ! array_key_exists($name, $record->getModified())
                    )) {
                        $record->$name = $this->buildSlugFromFields($record);
                    } else if ( ! empty($record->$name) &&
                        false !== $this->_options['canUpdate'] &&
                        array_key_exists($name, $record->getModified()
                    )) {
                        $record->$name = $this->buildSlugFromSlugField($record);
                    }
                }
            }
        {code}

        Change to

        {code}
            /**
             * Set the slug value automatically when a record is updated if the options are configured
             * to allow it
             *
             * @param Doctrine_Event $event
             * @return void
             */
            public function preUpdate(Doctrine_Event $event)
            {
                    $record = $event->getInvoker();
                    $name = $record->getTable()->getFieldName($this->_options['name']);

                    if ( ! $record->$name || (
                        false !== $this->_options['canUpdate'] &&
                        ! array_key_exists($name, $record->getModified())
                    )) {
                        $record->$name = $this->buildSlugFromFields($record);
                    } else if ( ! empty($record->$name) &&
                        false !== $this->_options['canUpdate'] &&
                        array_key_exists($name, $record->getModified()
                    )) {
                        $record->$name = $this->buildSlugFromSlugField($record);
                    }
            }
        {code} ]
        Hide
        webPragmatist added a comment - - edited

        The patch by Jacob doesn't work. The reason for the unique check is to bypass appending a numeric value to the end of a slug in the even two exist.

        It just needs to somehow be directly sent to the urlize function.

        Show
        webPragmatist added a comment - - edited The patch by Jacob doesn't work. The reason for the unique check is to bypass appending a numeric value to the end of a slug in the even two exist. It just needs to somehow be directly sent to the urlize function.
        Hide
        Jacob Mather added a comment -

        I would just like to post an update after I've been able to test:

        The only functionality that i found actually broken was updating a slug with unique set to false.

        The reason was the wrapped if.

        If you set unique to false, slugs will still fail to update as canUpdate must also be set to true.

        The patch, so far as I can determine, does correct the underlying issue if a slug failing to update when unique is false and canUpdate is true.

        Show
        Jacob Mather added a comment - I would just like to post an update after I've been able to test: The only functionality that i found actually broken was updating a slug with unique set to false. The reason was the wrapped if. If you set unique to false, slugs will still fail to update as canUpdate must also be set to true. The patch, so far as I can determine, does correct the underlying issue if a slug failing to update when unique is false and canUpdate is true.

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DC-623, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Adwise Internetmarketing
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: