src/Utils/UrlKeyUtil.php
/**
     * Make's the passed URL key unique by adding/raising a number to the end.
     *
     * @param \TechDivision\Import\Subjects\UrlKeyAwareSubjectInterface $subject The subject to make the URL key unique for
     * @param array                                                     $entity  The entity to make the URL key unique for
     * @param string                                                    $urlKey  The URL key to make unique
     * @param string|null                                               $urlPath The URL path to make unique (only used for categories)
     *
     * @return string The unique URL key
     */
Make's the passed URL key unique by adding/raising a number to the end.
@param \TechDivision\Import\Subjects\UrlKeyAwareSubjectInterface $subject The subject to make the URL key unique for
@param array                                                     $entity  The entity to make the URL key unique for
@param string                                                    $urlKey  The URL key to make unique
@param string|null                                               $urlPath The URL path to make unique (only used for categories)

@return string The unique URL key
Make ' s the passed URL key unique by adding / raising a number to the end . @param \ TechDivision \ Import \ Subjects \ UrlKeyAwareSubjectInterface $subject The subject to make the URL key unique for @param array $entity The entity to make the URL key unique for @param string $urlKey The URL key to make unique @param string|null $urlPath The URL path to make unique ( only used for categories ) @return string The unique URL key
protected function doMakeUnique(UrlKeyAwareSubjectInterface $subject, array $entity, string $urlKey, string $urlPath = null) : string
    {
        $storeId = (int) $subject->getRowStoreId();
        $entityTypeCode = $subject->getEntityTypeCode();
        $entityId = (int) $entity[MemberNames::ENTITY_ID];
        $entityType = (string) $this->urlRewriteEntityType;
        $counter = 0;
        s
        $matchingCounters = array();
        $notMatchingCounters = array();
        $url = $urlPath ? sprintf('%s/%s', $urlPath, $urlKey) : $urlKey;
        do {
            $requestPath = sprintf('%s%s', $url, $this->suffixes[$entityTypeCode][$storeId]);
            $urlRewrite = $this->loadUrlRewriteByRequestPathAndStoreId($requestPath, $storeId);
            if ($urlRewrite) {
                if (((int) $urlRewrite[MemberNames::ENTITY_ID]   === $entityId) &&
                    ((int) $urlRewrite[MemberNames::STORE_ID]    === $storeId) &&
                           $urlRewrite[MemberNames::ENTITY_TYPE] === $entityType
                ) {
                    $matchingCounters[] = $counter;
                    break;
                } else {
                    $notMatchingCounters[] = $counter;
                }
                $url = sprintf('%s-%d', $urlKey, ++$counter);
            } else {
                $this->getUrlKeyAwareProcessor()->persistUrlRewrite(
                    array(
                        MemberNames::URL_REWRITE_ID => md5(sprintf('%d-%s', $storeId, $requestPath)),
                        MemberNames::REDIRECT_TYPE  => 0,
                        MemberNames::STORE_ID       => $storeId,
                        MemberNames::ENTITY_ID      => $entityId,
                        MemberNames::REQUEST_PATH   => $requestPath,
                        MemberNames::ENTITY_TYPE    => $entityType,
                        EntityStatus::MEMBER_NAME   => EntityStatus::STATUS_CREATE
                    )
                );
            }
        } while ($urlRewrite);
        asort($matchingCounters);
        asort($notMatchingCounters);
        if (sizeof($matchingCounters) > 0) {
            $counter = end($matchingCounters);
            if ($counter > 0) {
                $urlKey = sprintf('%s-%d', $urlKey, $counter);
            }
        } elseif (sizeof($notMatchingCounters) > 0) {
            $newCounter = end($notMatchingCounters);
            $urlKey = sprintf('%s-%d', $urlKey, ++$newCounter);
        }
        return $urlKey;
    }
protected function doMakeUnique ( UrlKeyAwareSubjectInterface $ subject , array $ entity , string $ urlKey , string $ urlPath = null ) : string { $ storeId = ( int ) $ subject -> getRowStoreId ( ) ; $ entityTypeCode = $ subject -> getEntityTypeCode ( ) ; $ entityId = ( int ) $ entity [ MemberNames :: ENTITY_ID ] ; $ entityType = ( string ) $ this -> urlRewriteEntityType ; $ counter = 0 ; $ matchingCounters = array ( ) ; $ notMatchingCounters = array ( ) ; $ url = $ urlPath ? sprintf ( '%s/%s' , $ urlPath , $ urlKey ) : $ urlKey ; do { $ requestPath = sprintf ( '%s%s' , $ url , $ this -> suffixes [ $ entityTypeCode ] [ $ storeId ] ) ; $ urlRewrite = $ this -> loadUrlRewriteByRequestPathAndStoreId ( $ requestPath , $ storeId ) ; if ( $ urlRewrite ) { if ( ( ( int ) $ urlRewrite [ MemberNames :: ENTITY_ID ] === $ entityId ) && ( ( int ) $ urlRewrite [ MemberNames :: STORE_ID ] === $ storeId ) && $ urlRewrite [ MemberNames :: ENTITY_TYPE ] === $ entityType ) { $ matchingCounters [ ] = $ counter ; break ; } else { $ notMatchingCounters [ ] = $ counter ; } $ url = sprintf ( '%s-%d' , $ urlKey , ++ $ counter ) ; } else { $ this -> getUrlKeyAwareProcessor ( ) -> persistUrlRewrite ( array ( MemberNames :: URL_REWRITE_ID => md5 ( sprintf ( '%d-%s' , $ storeId , $ requestPath ) ) , MemberNames :: REDIRECT_TYPE => 0 , MemberNames :: STORE_ID => $ storeId , MemberNames :: ENTITY_ID => $ entityId , MemberNames :: REQUEST_PATH => $ requestPath , MemberNames :: ENTITY_TYPE => $ entityType , EntityStatus :: MEMBER_NAME => EntityStatus :: STATUS_CREATE ) ) ; } } while ( $ urlRewrite ) ; asort ( $ matchingCounters ) ; asort ( $ notMatchingCounters ) ; if ( sizeof ( $ matchingCounters ) > 0 ) { $ counter = end ( $ matchingCounters ) ; if ( $ counter > 0 ) { $ urlKey = sprintf ( '%s-%d' , $ urlKey , $ counter ) ; } } elseif ( sizeof ( $ notMatchingCounters ) > 0 ) { $ newCounter = end ( $ notMatchingCounters ) ; $ urlKey = sprintf ( '%s-%d' , $ urlKey , ++ $ newCounter ) ; } return $ urlKey ; }
Make's the passed URL key unique by adding/raising a number to the end.
Make ' s the passed URL key unique by adding / raising a number to the end .
// initialize the store view ID, use the default store view if no store view has // been set, because the default url_key value has been set in default store view // initialize entity ID + type from the passed entity // initialize the counter // initialize the counters // pre-initialze the URL by concatenating path and/or key to query for // prepare the request path to load an existing URL rewrite // try to load an existing URL rewrite // query whether or not an entity with the given // request path and store ID is available // if yes, query if this IS the URL key of the passed entity // add the matching counter // stop further processing here, because we've a matching // URL key and that's all we want for the moment // prepare the next URL key to query for // we've temporary persist a dummy URL rewrite to keep track of the new URL key, e. g. for // the case the import contains another product or category that wants to use the same one // sort the array ascending according to the counter // this IS the URL key of the passed entity => we've an UPDATE // load highest counter // if the counter is > 0, we've to append it to the new URL key // load the last entry that contains the // the last NOT matching counter // create a new URL key by raising the counter // return the passed URL key, if NOT