idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
11,500
private function persistRoute ( ResourceSegmentBehavior $ document ) { $ resourceLocatorStrategy = $ this -> resourceLocatorStrategyPool -> getStrategyByWebspaceKey ( $ this -> documentInspector -> getWebspace ( $ document ) ) ; $ resourceLocatorStrategy -> save ( $ document , null ) ; }
Creates or updates the route of the document using the RlpStrategy .
11,501
private function updateRoute ( $ document , $ generateRoutes ) { $ locales = $ this -> documentInspector -> getLocales ( $ document ) ; $ webspaceKey = $ this -> documentInspector -> getWebspace ( $ document ) ; $ uuid = $ this -> documentInspector -> getUuid ( $ document ) ; $ path = $ this -> documentInspector -> getPath ( $ document ) ; $ parentUuid = $ this -> documentInspector -> getUuid ( $ this -> documentInspector -> getParent ( $ document ) ) ; $ defaultNode = $ this -> defaultSession -> getNode ( $ path ) ; $ liveNode = $ this -> liveSession -> getNode ( $ path ) ; $ resourceLocatorStrategy = $ this -> resourceLocatorStrategyPool -> getStrategyByWebspaceKey ( $ webspaceKey ) ; foreach ( $ locales as $ locale ) { $ localizedDocument = $ this -> documentManager -> find ( $ uuid , $ locale ) ; if ( RedirectType :: NONE !== $ localizedDocument -> getRedirectType ( ) ) { continue ; } $ resourceSegmentPropertyName = $ this -> encoder -> localizedSystemName ( $ this -> getResourceSegmentProperty ( $ localizedDocument ) -> getName ( ) , $ locale ) ; $ this -> updateResourceSegmentProperty ( $ defaultNode , $ resourceSegmentPropertyName , $ parentUuid , $ webspaceKey , $ locale ) ; if ( $ liveNode -> hasProperty ( $ resourceSegmentPropertyName ) ) { $ this -> updateResourceSegmentProperty ( $ liveNode , $ resourceSegmentPropertyName , $ parentUuid , $ webspaceKey , $ locale ) ; if ( $ generateRoutes ) { $ localizedDocument -> setResourceSegment ( $ liveNode -> getPropertyValue ( $ resourceSegmentPropertyName ) ) ; $ resourceLocatorStrategy -> save ( $ localizedDocument , null ) ; $ localizedDocument -> setResourceSegment ( $ defaultNode -> getPropertyValue ( $ resourceSegmentPropertyName ) ) ; } } } }
Updates the route for the given document after a move or copy .
11,502
private function updateResourceSegmentProperty ( NodeInterface $ node , $ resourceSegmentPropertyName , $ parentUuid , $ webspaceKey , $ locale ) { $ resourceLocatorStrategy = $ this -> resourceLocatorStrategyPool -> getStrategyByWebspaceKey ( $ webspaceKey ) ; $ childPart = $ resourceLocatorStrategy -> getChildPart ( $ node -> getPropertyValue ( $ resourceSegmentPropertyName ) ) ; $ node -> setProperty ( $ resourceSegmentPropertyName , $ resourceLocatorStrategy -> generate ( $ childPart , $ parentUuid , $ webspaceKey , $ locale ) ) ; }
Updates the property for the resource segment on the given node .
11,503
private function handle ( Request $ request ) { $ kernel = $ this -> kernelFactory -> create ( $ this -> environment ) ; try { return $ kernel -> handle ( $ request , HttpKernelInterface :: MASTER_REQUEST , false ) ; } catch ( HttpException $ e ) { if ( $ e -> getPrevious ( ) ) { throw $ e -> getPrevious ( ) ; } throw $ e ; } }
Handles given request and returns response .
11,504
private function createServerAttributes ( PortalInformation $ portalInformation , Request $ currentRequest = null ) { $ server = [ ] ; $ host = null ; $ scheme = 'http' ; $ port = 80 ; if ( $ currentRequest ) { $ server = $ currentRequest -> server -> all ( ) ; $ scheme = $ currentRequest -> getScheme ( ) ; $ host = $ currentRequest -> getHost ( ) ; $ port = $ currentRequest -> getPort ( ) ; } $ portalUrl = $ scheme . '://' . $ this -> replacer -> replaceHost ( $ portalInformation -> getUrl ( ) , $ host ) ; $ portalUrlParts = parse_url ( $ portalUrl ) ; $ prefixPath = isset ( $ portalUrlParts [ 'path' ] ) ? $ portalUrlParts [ 'path' ] : '' ; $ httpHost = $ portalUrlParts [ 'host' ] ; if ( ! in_array ( $ port , [ 80 , 443 ] ) ) { $ httpHost .= ':' . $ port ; } $ server [ 'SERVER_NAME' ] = $ portalUrlParts [ 'host' ] ; $ server [ 'SERVER_PORT' ] = $ port ; $ server [ 'HTTP_HOST' ] = $ httpHost ; $ server [ 'REQUEST_URI' ] = $ prefixPath . '/_sulu_preview' ; unset ( $ server [ 'HTTP_X_REQUESTED_WITH' ] ) ; return $ server ; }
Create server attributes .
11,505
private function createPortalInformation ( $ object , $ id , $ webspaceKey , $ locale ) { $ webspace = $ this -> webspaceManager -> findWebspaceByKey ( $ webspaceKey ) ; $ domain = $ this -> requestStack -> getCurrentRequest ( ) -> getHost ( ) ; if ( ! $ webspace ) { throw new WebspaceNotFoundException ( $ object , $ id , $ webspaceKey , $ locale ) ; } $ webspace = clone $ webspace ; $ localization = $ webspace -> getLocalization ( $ locale ) ; if ( ! $ localization ) { throw new WebspaceLocalizationNotFoundException ( $ object , $ id , $ webspaceKey , $ locale ) ; } $ localization = clone $ localization ; $ localization -> setXDefault ( true ) ; $ portal = new Portal ( ) ; $ portal -> setName ( $ webspace -> getName ( ) ) ; $ portal -> setKey ( $ webspace -> getKey ( ) ) ; $ portal -> setWebspace ( $ webspace ) ; $ portal -> setXDefaultLocalization ( $ localization ) ; $ portal -> setLocalizations ( [ $ localization ] ) ; $ portal -> setDefaultLocalization ( $ localization ) ; $ environment = new Environment ( ) ; $ url = new Url ( $ domain , $ this -> environment ) ; $ environment -> setUrls ( [ $ url ] ) ; $ portal -> setEnvironments ( [ $ environment ] ) ; $ webspace -> setPortals ( [ $ portal ] ) ; return new PortalInformation ( RequestAnalyzer :: MATCH_TYPE_FULL , $ webspace , $ portal , $ localization , $ domain ) ; }
This creates a new portal information based on the given information . This is necessary because it is possible that a webspace defines a language which is not used in any portal . For this case we have to define our own fake PortalInformation object .
11,506
public function createNodeInPublicWorkspace ( PersistEvent $ event ) { $ node = $ event -> getNode ( ) ; if ( $ node -> isNew ( ) ) { $ this -> createNodesWithUuid ( $ node ) ; return ; } $ liveNode = $ this -> getLiveNode ( $ event -> getDocument ( ) ) ; $ nodeName = $ node -> getName ( ) ; if ( $ liveNode -> getName ( ) !== $ nodeName ) { $ liveNode -> rename ( $ nodeName ) ; } }
Creates the node with the same UUID in the public workspace if it does not exist yet . In case it does it will be renamed if necessary .
11,507
public function removeNodeFromPublicWorkspace ( RemoveEvent $ event ) { $ document = $ event -> getDocument ( ) ; $ metadata = $ this -> metadataFactory -> getMetadataForClass ( get_class ( $ document ) ) ; if ( ! $ metadata -> getSyncRemoveLive ( ) ) { return ; } $ this -> getLiveNode ( $ document ) -> remove ( ) ; }
Since deleting is not draftable the node will be deleted in the live session as soon as it is deleted in the default session .
11,508
public function moveNodeInPublicWorkspace ( MoveEvent $ event ) { $ liveNode = $ this -> getLiveNode ( $ event -> getDocument ( ) ) ; $ this -> nodeHelper -> move ( $ liveNode , $ event -> getDestId ( ) , $ event -> getDestName ( ) ) ; }
Since moving is not draftable the node will also be moved in the live session immediately .
11,509
public function reorderNodeInPublicWorkspace ( ReorderEvent $ event ) { $ node = $ this -> getLiveNode ( $ event -> getDocument ( ) ) ; $ this -> nodeHelper -> reorder ( $ node , $ event -> getDestId ( ) ) ; $ count = 1 ; foreach ( $ node -> getParent ( ) -> getNodes ( ) as $ childNode ) { $ childNode -> setProperty ( $ this -> propertyEncoder -> systemName ( 'order' ) , $ count * 10 ) ; ++ $ count ; } }
Reordering is also not draftable and therefore also immediately applied to the live session .
11,510
public function removePropertiesFromPublicWorkspace ( UnpublishEvent $ event ) { $ node = $ event -> getNode ( ) ; $ locale = $ event -> getLocale ( ) ; $ this -> removeLocalizedNodeProperties ( $ node , $ locale ) ; }
Removes all the properties for the given locale from the node so that the content is not accessible anymore from the live workspace .
11,511
private function createNodesWithUuid ( NodeInterface $ node ) { $ path = $ node -> getPath ( ) ; if ( $ this -> liveSession -> itemExists ( $ path ) ) { return ; } $ currentDefaultNode = $ node -> getSession ( ) -> getRootNode ( ) ; $ currentLiveNode = $ this -> liveSession -> getRootNode ( ) ; $ pathSegments = explode ( '/' , ltrim ( $ path , '/' ) ) ; foreach ( $ pathSegments as $ pathSegment ) { $ currentDefaultNode = $ currentDefaultNode -> getNode ( $ pathSegment ) ; if ( $ currentLiveNode -> hasNode ( $ pathSegment ) ) { $ currentLiveNode = $ currentLiveNode -> getNode ( $ pathSegment ) ; continue ; } $ currentLiveNode = $ currentLiveNode -> addNode ( $ pathSegment ) ; $ currentLiveNode -> setMixins ( [ 'mix:referenceable' ] ) ; $ currentLiveNode -> setProperty ( 'jcr:uuid' , $ currentDefaultNode -> getIdentifier ( ) ) ; } }
Creates every node on the path to the given node . Also uses the same UUIDs for these nodes .
11,512
private function removeLocalizedNodeProperties ( NodeInterface $ node , $ locale ) { foreach ( $ node -> getProperties ( $ this -> propertyEncoder -> localizedSystemName ( '' , $ locale ) . '*' ) as $ property ) { $ property -> remove ( ) ; } foreach ( $ node -> getProperties ( $ this -> propertyEncoder -> localizedContentName ( '' , $ locale ) . '*' ) as $ property ) { $ property -> remove ( ) ; } }
Removes all localized properties in the given locale from the given node .
11,513
private function loadProperties ( & $ tags , \ DOMXPath $ xpath , \ DOMNode $ context ) : array { $ result = [ ] ; foreach ( $ xpath -> query ( 'x:*' , $ context ) as $ node ) { if ( 'property' === $ node -> tagName ) { $ value = $ this -> loadProperty ( $ xpath , $ node , $ tags ) ; $ result [ $ value [ 'name' ] ] = $ value ; } elseif ( 'block' === $ node -> tagName ) { $ value = $ this -> loadBlock ( $ xpath , $ node , $ tags ) ; $ result [ $ value [ 'name' ] ] = $ value ; } elseif ( 'section' === $ node -> tagName ) { $ value = $ this -> loadSection ( $ xpath , $ node , $ tags ) ; $ result [ $ value [ 'name' ] ] = $ value ; } } return $ result ; }
load properties from given context .
11,514
private function loadProperty ( \ DOMXPath $ xpath , \ DOMNode $ node , & $ tags ) { $ result = $ this -> loadValues ( $ xpath , $ node , [ 'name' , 'type' , 'minOccurs' , 'maxOccurs' , 'colspan' , 'cssClass' , 'spaceAfter' , 'disabledCondition' , 'visibleCondition' , ] ) ; $ result [ 'mandatory' ] = $ this -> getValueFromXPath ( '@mandatory' , $ xpath , $ node , false ) ; $ result [ 'multilingual' ] = $ this -> getValueFromXPath ( '@multilingual' , $ xpath , $ node , true ) ; $ result [ 'onInvalid' ] = $ this -> getValueFromXPath ( '@onInvalid' , $ xpath , $ node ) ; $ result [ 'tags' ] = $ this -> loadTags ( $ tags , $ xpath , $ node ) ; $ result [ 'params' ] = $ this -> loadParams ( 'x:params/x:param' , $ xpath , $ node ) ; $ result [ 'meta' ] = $ this -> loadMeta ( $ xpath , $ node ) ; return $ result ; }
load single property .
11,515
private function validateTag ( $ tag , & $ tags ) { if ( ! isset ( $ tags [ $ tag [ 'name' ] ] ) ) { $ tags [ $ tag [ 'name' ] ] = [ ] ; } $ tags [ $ tag [ 'name' ] ] [ ] = $ tag [ 'priority' ] ; }
validates a single tag .
11,516
private function loadTag ( \ DOMXPath $ xpath , \ DOMNode $ node ) { $ tag = [ 'name' => null , 'priority' => null , 'attributes' => [ ] , ] ; foreach ( $ node -> attributes as $ key => $ attr ) { if ( in_array ( $ key , [ 'name' , 'priority' ] ) ) { $ tag [ $ key ] = $ attr -> value ; } else { $ tag [ 'attributes' ] [ $ key ] = $ attr -> value ; } } return $ tag ; }
load single tag .
11,517
private function loadBlock ( \ DOMXPath $ xpath , \ DOMNode $ node , & $ tags ) { $ result = $ this -> loadValues ( $ xpath , $ node , [ 'name' , 'default-type' , 'minOccurs' , 'maxOccurs' , 'colspan' , 'cssClass' , 'disabledCondition' , 'visibleCondition' , ] ) ; $ result [ 'mandatory' ] = $ this -> getValueFromXPath ( '@mandatory' , $ xpath , $ node , false ) ; $ result [ 'type' ] = 'block' ; $ result [ 'tags' ] = $ this -> loadTags ( $ tags , $ xpath , $ node ) ; $ result [ 'params' ] = $ this -> loadParams ( 'x:params/x:param' , $ xpath , $ node ) ; $ result [ 'meta' ] = $ this -> loadMeta ( $ xpath , $ node ) ; $ result [ 'types' ] = $ this -> loadTypes ( $ tags , $ xpath , $ node ) ; return $ result ; }
load single block .
11,518
private function loadTags ( & $ tags , \ DOMXPath $ xpath , \ DOMNode $ context = null ) { $ result = [ ] ; foreach ( $ xpath -> query ( 'x:tag' , $ context ) as $ node ) { $ tag = $ this -> loadTag ( $ xpath , $ node ) ; $ this -> validateTag ( $ tag , $ tags ) ; $ result [ ] = $ tag ; } return $ result ; }
load tags from given tag and validates them .
11,519
private function loadTypes ( & $ tags , \ DOMXPath $ xpath , \ DOMNode $ context = null ) { $ result = [ ] ; foreach ( $ xpath -> query ( 'x:types/x:type' , $ context ) as $ node ) { $ value = $ this -> loadType ( $ xpath , $ node , $ tags ) ; $ result [ $ value [ 'name' ] ] = $ value ; } return $ result ; }
load types from given node .
11,520
private function loadValues ( \ DOMXPath $ xpath , \ DOMNode $ node , $ keys , $ prefix = '@' ) { $ result = [ ] ; foreach ( $ keys as $ key ) { $ result [ $ key ] = $ this -> getValueFromXPath ( $ prefix . $ key , $ xpath , $ node ) ; } return $ result ; }
load values defined by key from given node .
11,521
private function loadParams ( $ path , \ DOMXPath $ xpath , \ DOMNode $ context = null ) { $ result = [ ] ; foreach ( $ xpath -> query ( $ path , $ context ) as $ node ) { $ result [ ] = $ this -> loadParam ( $ xpath , $ node ) ; } return $ result ; }
load params from given node .
11,522
public function setAddress ( \ Sulu \ Bundle \ ContactBundle \ Entity \ Address $ address ) { $ this -> address = $ address ; return $ this ; }
Set address .
11,523
private function isUnique ( RouteInterface $ route ) { $ persistedRoute = $ this -> routeRepository -> findByPath ( $ route -> getPath ( ) , $ route -> getLocale ( ) ) ; return ! $ persistedRoute ; }
Returns true if route is unique .
11,524
private function resolve ( RouteInterface $ route , RoutableInterface $ entity ) { $ persistedRoute = $ this -> routeRepository -> findByPath ( $ route -> getPath ( ) , $ route -> getLocale ( ) ) ; if ( ! $ persistedRoute ) { return $ route ; } if ( $ persistedRoute -> getEntityClass ( ) === $ route -> getEntityClass ( ) && $ persistedRoute -> getEntityId ( ) === $ route -> getEntityId ( ) ) { return $ persistedRoute ; } throw new RouteIsNotUniqueException ( $ route , $ entity ) ; }
Looks for the same route in the database . If no route was found the method returns the newly created route . If the route is a history route for given entity the history route will be returned . Else a RouteIsNotUniqueException will be thrown .
11,525
public function setBlamesOnDocument ( HydrateEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ this -> supports ( $ document ) ) { return ; } $ node = $ event -> getNode ( ) ; $ locale = $ event -> getLocale ( ) ; $ encoding = $ this -> getPropertyEncoding ( $ document ) ; $ accessor = $ event -> getAccessor ( ) ; $ accessor -> set ( static :: CHANGER , $ node -> getPropertyValueWithDefault ( $ this -> propertyEncoder -> encode ( $ encoding , static :: CHANGER , $ locale ) , null ) ) ; $ accessor -> set ( static :: CREATOR , $ node -> getPropertyValueWithDefault ( $ this -> propertyEncoder -> encode ( $ encoding , static :: CREATOR , $ locale ) , null ) ) ; }
Sets the changer and creator of the document .
11,526
public function setBlamesOnNodeForPersist ( PersistEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ this -> supports ( $ document ) ) { return ; } $ this -> setBlamesOnNode ( $ document , $ event -> getNode ( ) , $ event -> getLocale ( ) , $ event -> getAccessor ( ) , $ event -> getOption ( 'user' ) ) ; }
Sets the creator and changer for the persist event .
11,527
public function setBlamesOnNodeForPublish ( PublishEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ this -> supports ( $ document ) ) { return ; } $ this -> setBlamesOnNode ( $ document , $ event -> getNode ( ) , $ event -> getLocale ( ) , $ event -> getAccessor ( ) , $ document -> getChanger ( ) ) ; }
Sets the creator and changer for the publish event .
11,528
public function setBlamesOnNode ( LocalizedBlameBehavior $ document , NodeInterface $ node , $ locale , DocumentAccessor $ accessor , $ userId ) { if ( ! $ document instanceof BlameBehavior && ! $ locale ) { return ; } $ encoding = $ this -> getPropertyEncoding ( $ document ) ; $ creatorPropertyName = $ this -> propertyEncoder -> encode ( $ encoding , static :: CREATOR , $ locale ) ; if ( ! $ node -> hasProperty ( $ creatorPropertyName ) ) { $ accessor -> set ( self :: CREATOR , $ userId ) ; $ node -> setProperty ( $ creatorPropertyName , $ document -> getCreator ( ) ) ; } $ accessor -> set ( self :: CHANGER , $ userId ) ; $ node -> setProperty ( $ this -> propertyEncoder -> encode ( $ encoding , static :: CHANGER , $ locale ) , $ userId ) ; }
Persists the data of creator and changer to the Node .
11,529
public function setChangerForRestore ( RestoreEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ this -> supports ( $ event -> getDocument ( ) ) ) { return ; } $ encoding = $ this -> getPropertyEncoding ( $ document ) ; $ event -> getNode ( ) -> setProperty ( $ this -> propertyEncoder -> encode ( $ encoding , self :: CHANGER , $ event -> getLocale ( ) ) , $ event -> getOption ( 'user' ) ) ; }
Sets the changer for the restore event .
11,530
private function evaluateTargetGroup ( TargetGroupInterface $ targetGroup ) { foreach ( $ targetGroup -> getRules ( ) as $ targetGroupRule ) { if ( $ this -> evaluateTargetGroupRule ( $ targetGroupRule ) ) { return true ; } } return false ; }
Evaluates if one of the rules of the given TargetGroup match . If one of these rules are matching the entire target group is matching .
11,531
private function evaluateTargetGroupRule ( TargetGroupRuleInterface $ targetGroupRule ) { foreach ( $ targetGroupRule -> getConditions ( ) as $ targetGroupCondition ) { $ rule = $ this -> ruleCollection -> getRule ( $ targetGroupCondition -> getType ( ) ) ; if ( ! $ rule -> evaluate ( $ targetGroupCondition -> getCondition ( ) ) ) { return false ; } } return true ; }
Evaluates if the given rule is matching . Only returns true if all of the conditions are matching .
11,532
public function addParameters ( array $ params ) { if ( ! is_array ( $ params ) ) { throw new \ InvalidArgumentException ( '$params has to be an array' ) ; } $ this -> parameters = array_merge ( $ this -> parameters , $ params ) ; }
adds array of parameters .
11,533
private function processNavigationItem ( NavigationItem $ navigationItem ) : void { if ( ! $ navigationItem -> getLabel ( ) ) { $ navigationItem -> setLabel ( $ this -> translator -> trans ( $ navigationItem -> getName ( ) , [ ] , 'admin' ) ) ; } if ( $ navigationItem -> getMainRoute ( ) ) { $ mainPath = $ this -> routeRegistry -> findRouteByName ( $ navigationItem -> getMainRoute ( ) ) -> getPath ( ) ; foreach ( $ this -> routeRegistry -> getRoutes ( ) as $ route ) { if ( false !== strpos ( $ route -> getPath ( ) , $ mainPath ) ) { $ navigationItem -> addChildRoute ( $ route -> getName ( ) ) ; } } } foreach ( $ navigationItem -> getChildren ( ) as $ child ) { $ this -> processNavigationItem ( $ child ) ; } }
Adds the translation and the child routes to the given navigation item .
11,534
public function getAlternateLinks ( $ urls ) { $ webspaceKey = $ this -> requestAnalyzer -> getWebspace ( ) -> getKey ( ) ; $ currentPortal = $ this -> requestAnalyzer -> getPortal ( ) ; $ defaultLocale = null ; if ( null !== $ currentPortal && null !== ( $ defaultLocale = $ currentPortal -> getXDefaultLocalization ( ) ) ) { $ defaultLocale = $ defaultLocale -> getLocale ( ) ; } $ result = [ ] ; foreach ( $ urls as $ locale => $ url ) { if ( '/' !== $ url || '/' === $ this -> requestAnalyzer -> getResourceLocator ( ) ) { if ( $ locale === $ defaultLocale ) { $ result [ ] = $ this -> getAlternate ( $ url , $ webspaceKey , $ locale , true ) ; } $ result [ ] = $ this -> getAlternate ( $ url , $ webspaceKey , $ locale ) ; } } return implode ( PHP_EOL , $ result ) ; }
Returns alternate link HTML tags with href - lang attributes .
11,535
public function getSeoMetaTags ( $ extension , $ content ) { $ seo = [ ] ; if ( array_key_exists ( 'seo' , $ extension ) ) { $ seo = $ extension [ 'seo' ] ; } $ excerpt = [ ] ; if ( array_key_exists ( 'excerpt' , $ extension ) ) { $ excerpt = $ extension [ 'excerpt' ] ; } if ( ( ! array_key_exists ( 'description' , $ seo ) || '' === $ seo [ 'description' ] ) && array_key_exists ( 'description' , $ excerpt ) && '' !== $ excerpt [ 'description' ] ) { $ seo [ 'description' ] = strip_tags ( $ excerpt [ 'description' ] ) ; } $ seo [ 'description' ] = substr ( $ seo [ 'description' ] , 0 , 155 ) ; $ robots = [ ] ; $ robots [ ] = ( array_key_exists ( 'noIndex' , $ seo ) && true === $ seo [ 'noIndex' ] ) ? 'noIndex' : 'index' ; $ robots [ ] = ( array_key_exists ( 'noFollow' , $ seo ) && true === $ seo [ 'noFollow' ] ) ? 'noFollow' : 'follow' ; $ result = [ ] ; $ result [ ] = $ this -> getMeta ( 'description' , $ seo [ 'description' ] ) ; $ result [ ] = $ this -> getMeta ( 'keywords' , $ seo [ 'keywords' ] ) ; $ result [ ] = $ this -> getMeta ( 'robots' , strtoupper ( implode ( ', ' , $ robots ) ) ) ; return implode ( PHP_EOL , $ result ) ; }
Returns seo meta tags with fallbacks .
11,536
private function addFormatFromFormatNode ( \ DOMNode $ formatNode , & $ formats ) { $ key = $ this -> getKeyFromFormatNode ( $ formatNode ) ; $ internal = $ this -> getInternalFlagFromFormatNode ( $ formatNode ) ; $ meta = $ this -> getMetaFromFormatNode ( $ formatNode ) ; $ scale = $ this -> getScaleFromFormatNode ( $ formatNode ) ; $ transformations = $ this -> getTransformationsFromFormatNode ( $ formatNode ) ; $ options = $ this -> getOptionsFromFormatNode ( $ formatNode ) ; $ formats [ $ key ] = [ 'key' => $ key , 'internal' => $ internal , 'meta' => $ meta , 'scale' => $ scale , 'transformations' => $ transformations , 'options' => array_merge ( $ this -> globalOptions , $ options ) , ] ; }
For a given format node and a given array of formats this method parses the format node to an array and adds it to the formats array .
11,537
private function tryLoad ( $ file ) { try { return XmlUtils :: loadFile ( $ file , __DIR__ . static :: SCHEME_PATH ) ; } catch ( \ InvalidArgumentException $ e ) { throw new InvalidMediaFormatException ( sprintf ( 'Could not parse image formats XML file "%s"' , $ file ) , null , $ e ) ; } }
Tries to load the DOM Document of a given image formats xml .
11,538
protected function getParametersFromNode ( $ node , $ parameterName = 'parameter' ) { if ( null === $ node ) { return [ ] ; } $ parameters = [ ] ; foreach ( $ this -> xpath -> query ( 'x:' . $ parameterName , $ node ) as $ parameterNode ) { $ name = $ this -> xpath -> query ( '@name' , $ parameterNode ) -> item ( 0 ) -> nodeValue ; $ parameters [ $ name ] = $ parameterNode -> nodeValue ; } return $ parameters ; }
For a given dom node returns an array of parameters . The xml name of the parameter tag can be passed as an argument .
11,539
private function getOptionsFromFormatNode ( \ DOMNode $ formatNode ) { $ optionsNode = $ this -> xpath -> query ( 'x:options' , $ formatNode ) -> item ( 0 ) ; return $ this -> getParametersFromNode ( $ optionsNode , 'option' ) ; }
For a given format node returns the options for it .
11,540
private function findAvailableParentLocalization ( array $ availableLocales , Localization $ localization ) { do { if ( in_array ( $ localization -> getLocale ( ) , $ availableLocales ) ) { return $ localization ; } $ localization = $ localization -> getParent ( ) ; } while ( null != $ localization ) ; return ; }
Finds the next available parent - localization in which the node has a translation .
11,541
private function findAvailableChildLocalization ( array $ availableLocales , Localization $ localization ) { $ childrenLocalizations = $ localization -> getChildren ( ) ; if ( ! empty ( $ childrenLocalizations ) ) { foreach ( $ childrenLocalizations as $ childrenLocalization ) { if ( in_array ( $ childrenLocalization -> getLocale ( ) , $ availableLocales ) ) { return $ childrenLocalization ; } return $ this -> findAvailableChildLocalization ( $ availableLocales , $ childrenLocalization ) ; } } return ; }
Finds the next available child - localization in which the node has a translation .
11,542
private function findAvailableLocalization ( array $ availableLocales , array $ localizations ) { foreach ( $ localizations as $ localization ) { if ( in_array ( $ localization -> getLocale ( ) , $ availableLocales ) ) { return $ localization ; } $ children = $ localization -> getChildren ( ) ; if ( $ children ) { $ result = $ this -> findAvailableLocalization ( $ availableLocales , $ children ) ; if ( null !== $ result ) { return $ result ; } } } return ; }
Finds any localization in which the node is translated .
11,543
private function findCategoriesWithoutParents ( ) { $ qb = $ this -> categoryRepository -> createQueryBuilder ( 'c2' ) -> select ( 'count(c2.id)' ) -> leftJoin ( 'c2.parent' , 'c1' ) -> where ( 'c2.depth <> 0 AND c2.parent IS NULL' ) ; return $ qb -> getQuery ( ) -> getSingleScalarResult ( ) ; }
Find number of categories that have no parent but depth > 0 .
11,544
private function fixWrongDepthGap ( ) { $ sql = 'UPDATE ca_categories c2 JOIN ca_categories c1 ON c2.idCategoriesParent = c1.id SET c2.depth = (c1.depth + 1) WHERE ( c2.depth - 1 ) <> c1.depth' ; $ statement = $ this -> entityManager -> getConnection ( ) -> prepare ( $ sql ) ; if ( $ statement -> execute ( ) ) { return $ statement -> rowCount ( ) ; } return false ; }
Fix categories where difference to parents depth .
11,545
private function fixCategoriesWithoutParents ( ) { $ qb = $ this -> categoryRepository -> createQueryBuilder ( 'c2' ) -> update ( ) -> set ( 'c2.depth' , 0 ) -> where ( 'c2.parent IS NULL AND c2.depth != 0' ) ; $ qb -> getQuery ( ) -> execute ( ) ; }
Set every category where depth > 0 and has no parents to depth 0 .
11,546
public function loadByArea ( $ area , $ webspaceKey = null , $ locale = null ) { if ( ! $ webspaceKey ) { $ webspaceKey = $ this -> requestAnalyzer -> getWebspace ( ) -> getKey ( ) ; } if ( ! $ locale ) { $ locale = $ this -> requestAnalyzer -> getCurrentLocalization ( ) -> getLocale ( ) ; } try { $ snippet = $ this -> defaultSnippetManager -> load ( $ webspaceKey , $ area , $ locale ) ; } catch ( WrongSnippetTypeException $ exception ) { return null ; } catch ( DocumentNotFoundException $ exception ) { return null ; } if ( ! $ snippet ) { return null ; } $ snippets = $ this -> snippetResolver -> resolve ( [ $ snippet -> getUuid ( ) ] , $ webspaceKey , $ locale ) ; if ( ! array_key_exists ( 0 , $ snippets ) ) { return null ; } return $ snippets [ 0 ] ; }
Load snippet for webspace by area .
11,547
private function addFileSystemNode ( ) { $ builder = new TreeBuilder ( ) ; $ node = $ builder -> root ( 'file_system' ) ; $ node -> addDefaultsIfNotSet ( ) -> children ( ) -> scalarNode ( 'directory' ) -> defaultValue ( '%sulu.cache_dir%/preview' ) -> end ( ) -> scalarNode ( 'extension' ) -> defaultNull ( ) -> end ( ) -> integerNode ( 'umask' ) -> defaultValue ( 0002 ) -> end ( ) -> end ( ) ; return $ node ; }
Build file_system node configuration definition .
11,548
private function addRedisNode ( ) { $ builder = new TreeBuilder ( ) ; $ node = $ builder -> root ( 'redis' ) ; $ node -> addDefaultsIfNotSet ( ) -> children ( ) -> scalarNode ( 'connection_id' ) -> defaultNull ( ) -> end ( ) -> scalarNode ( 'host' ) -> defaultValue ( '127.0.0.1' ) -> end ( ) -> scalarNode ( 'port' ) -> defaultValue ( '6379' ) -> end ( ) -> scalarNode ( 'password' ) -> defaultNull ( ) -> end ( ) -> scalarNode ( 'timeout' ) -> defaultNull ( ) -> end ( ) -> scalarNode ( 'database' ) -> defaultNull ( ) -> end ( ) -> end ( ) ; return $ node ; }
Build redis node configuration definition .
11,549
public function handleBlameTimestamp ( PreIndexEvent $ event ) { $ subject = $ event -> getSubject ( ) ; $ document = $ event -> getDocument ( ) ; if ( $ subject instanceof UserBlameInterface ) { $ this -> mapCreatorAndChanger ( $ document , $ subject -> getCreator ( ) , $ subject -> getChanger ( ) ) ; } if ( $ subject instanceof TimestampableInterface ) { $ this -> mapTimestamp ( $ document , $ subject -> getCreated ( ) , $ subject -> getChanged ( ) ) ; } }
Map blame and timestamp information to the search document .
11,550
private function getFieldValue ( $ document , $ fieldName ) { if ( false === $ document -> hasField ( $ fieldName ) ) { return ; } return $ document -> getField ( $ fieldName ) -> getValue ( ) ; }
Return the named field from the document or return null .
11,551
private function mapTimestamp ( Document $ document , \ DateTime $ created = null , \ DateTime $ changed = null ) { $ document -> addField ( $ this -> factory -> createField ( 'created' , $ created ? $ created -> format ( 'c' ) : null , 'string' ) ) ; $ document -> addField ( $ this -> factory -> createField ( 'changed' , $ changed ? $ changed -> format ( 'c' ) : null , 'string' ) ) ; }
Map timestamps to the search document .
11,552
private function mapCreatorAndChanger ( Document $ document , UserInterface $ creator = null , UserInterface $ changer = null ) { $ document -> addField ( $ this -> factory -> createField ( 'changer' , $ changer ? $ changer -> getUsername ( ) : null , 'string' ) ) ; $ document -> addField ( $ this -> factory -> createField ( 'changer_id' , $ changer ? $ changer -> getId ( ) : null , 'string' ) ) ; $ document -> addField ( $ this -> factory -> createField ( 'creator' , $ creator ? $ creator -> getUsername ( ) : null , 'string' ) ) ; $ document -> addField ( $ this -> factory -> createField ( 'creator_id' , $ creator ? $ creator -> getId ( ) : null , 'string' ) ) ; }
Map the creator and changer to the document .
11,553
protected function printExceptions ( $ import , $ output = null ) { if ( null === $ output ) { $ output = new NullOutput ( ) ; } $ output -> writeln ( [ '' , '' , '<info>Import Result</info>' , '<info>===============</info>' , '<info>' . $ import -> successes . ' Documents imported.</info>' , '<comment>' . count ( $ import -> failed ) . ' Documents ignored.</comment>' , ] ) ; if ( ! isset ( $ import -> exceptionStore [ 'ignore' ] ) ) { return ; } if ( count ( $ import -> exceptionStore [ 'ignore' ] ) > 20 ) { foreach ( $ import -> exceptionStore [ 'ignore' ] as $ msg ) { $ this -> logger -> info ( $ msg ) ; } return ; } foreach ( $ import -> exceptionStore [ 'ignore' ] as $ msg ) { $ output -> writeln ( '<comment>' . $ msg . '</comment>' ) ; $ this -> logger -> info ( $ msg ) ; } }
Print the completion message after import is done .
11,554
protected function parseXml ( $ file ) { $ this -> xpath = new \ DOMXPath ( $ this -> tryLoad ( $ file ) ) ; $ this -> xpath -> registerNamespace ( 'x' , 'http://schemas.sulu.io/webspace/webspace' ) ; $ this -> webspace = new Webspace ( ) ; $ this -> webspace -> setName ( $ this -> xpath -> query ( '/x:webspace/x:name' ) -> item ( 0 ) -> nodeValue ) ; $ this -> webspace -> setKey ( $ this -> xpath -> query ( '/x:webspace/x:key' ) -> item ( 0 ) -> nodeValue ) ; $ this -> webspace -> setTheme ( $ this -> generateTheme ( ) ) ; $ this -> webspace -> setNavigation ( $ this -> generateNavigation ( ) ) ; $ this -> webspace -> setResourceLocatorStrategy ( 'tree_leaf_edit' ) ; $ this -> generateTemplates ( $ this -> webspace ) ; $ this -> generateDefaultTemplates ( $ this -> webspace ) ; $ this -> generateSecurity ( ) ; $ this -> generateWebspaceLocalizations ( ) ; $ this -> generateSegments ( ) ; $ this -> generatePortals ( ) ; $ this -> validate ( ) ; return $ this -> webspace ; }
Parses the entire file and returns a webspace object .
11,555
protected function tryLoad ( $ file ) { try { return XmlUtils :: loadFile ( $ file , __DIR__ . static :: SCHEMA_LOCATION ) ; } catch ( \ InvalidArgumentException $ e ) { throw new InvalidWebspaceException ( sprintf ( 'Could not parse webspace XML file "%s"' , $ file ) , null , $ e ) ; } }
Returns xml - doc when one scheme matches .
11,556
protected function loadPortalLocalizationDefaultFromWebspace ( $ portal ) { $ webspaceDefaultLocalization = $ this -> webspace -> getDefaultLocalization ( ) ; foreach ( $ portal -> getLocalizations ( ) as $ localization ) { if ( $ webspaceDefaultLocalization && $ webspaceDefaultLocalization -> getLocale ( ) == $ localization -> getLocale ( ) ) { $ localization -> setDefault ( true ) ; $ portal -> setDefaultLocalization ( $ localization ) ; return true ; } } return false ; }
Sets the default localization for the given portal .
11,557
protected function generatePortalLocalizations ( \ DOMNode $ portalNode , Portal $ portal ) { if ( $ this -> xpath -> query ( 'x:localizations' , $ portalNode ) -> length > 0 ) { $ localizationNodes = $ this -> xpath -> query ( 'x:localizations/x:localization' , $ portalNode ) ; $ this -> generateLocalizationsFromNodeList ( $ localizationNodes , $ portal ) ; } else { $ localizationNodes = $ this -> xpath -> query ( '/x:webspace/x:localizations//x:localization' ) ; $ this -> generateLocalizationsFromNodeList ( $ localizationNodes , $ portal , true ) ; } }
Generates all localizations for the given portal .
11,558
protected function generateLocalizationsFromNodeList ( \ DOMNodeList $ localizationNodes , Portal $ portal , $ flat = false ) { foreach ( $ localizationNodes as $ localizationNode ) { $ localization = $ this -> generateLocalizationFromNode ( $ localizationNode , $ flat ) ; $ portal -> addLocalization ( $ localization ) ; } }
Generates the localizations for the given portal from the given DOMNodeList .
11,559
protected function generateLocalizationFromNode ( \ DOMElement $ localizationNode , $ flat = false , $ parent = null ) { $ localization = new Localization ( ) ; $ localization -> setLanguage ( $ localizationNode -> attributes -> getNamedItem ( 'language' ) -> nodeValue ) ; if ( $ parent ) { $ localization -> setParent ( $ parent ) ; } $ countryNode = $ localizationNode -> attributes -> getNamedItem ( 'country' ) ; if ( $ countryNode ) { $ localization -> setCountry ( $ countryNode -> nodeValue ) ; } $ shadowNode = $ localizationNode -> attributes -> getNamedItem ( 'shadow' ) ; if ( $ shadowNode ) { $ localization -> setShadow ( $ shadowNode -> nodeValue ) ; } $ defaultNode = $ localizationNode -> attributes -> getNamedItem ( 'default' ) ; if ( $ defaultNode ) { $ localization -> setDefault ( 'true' == $ defaultNode -> nodeValue ) ; } else { $ localization -> setDefault ( false ) ; } $ xDefaultNode = $ localizationNode -> attributes -> getNamedItem ( 'x-default' ) ; if ( $ xDefaultNode ) { $ localization -> setXDefault ( 'true' == $ xDefaultNode -> nodeValue ) ; } else { $ localization -> setXDefault ( false ) ; } if ( ! $ flat ) { foreach ( $ this -> xpath -> query ( 'x:localization' , $ localizationNode ) as $ childNode ) { $ localization -> addChild ( $ this -> generateLocalizationFromNode ( $ childNode , $ flat , $ localization ) ) ; } } return $ localization ; }
Generates a localization from the given node .
11,560
protected function generateSecurity ( ) { $ securitySystemNode = $ this -> xpath -> query ( '/x:webspace/x:security/x:system' ) ; if ( $ securitySystemNode -> length > 0 ) { $ security = new Security ( ) ; $ security -> setSystem ( $ securitySystemNode -> item ( 0 ) -> nodeValue ) ; $ this -> webspace -> setSecurity ( $ security ) ; } }
Generates and sets the security object from the XML document .
11,561
protected function generateWebspaceLocalizations ( ) { foreach ( $ this -> xpath -> query ( '/x:webspace/x:localizations/x:localization' ) as $ localizationNode ) { $ localization = $ this -> generateLocalizationFromNode ( $ localizationNode ) ; $ this -> webspace -> addLocalization ( $ localization ) ; } }
Generates the localization for the webspace from the XML document .
11,562
protected function generateSegments ( ) { foreach ( $ this -> xpath -> query ( '/x:webspace/x:segments/x:segment' ) as $ segmentNode ) { $ segment = new Segment ( ) ; $ segment -> setName ( $ segmentNode -> nodeValue ) ; $ segment -> setKey ( $ segmentNode -> attributes -> getNamedItem ( 'key' ) -> nodeValue ) ; $ defaultNode = $ segmentNode -> attributes -> getNamedItem ( 'default' ) ; if ( $ defaultNode ) { $ segment -> setDefault ( 'true' == $ defaultNode -> nodeValue ) ; } else { $ segment -> setDefault ( false ) ; } $ this -> webspace -> addSegment ( $ segment ) ; } }
Generates the available segments for the webspace from the XML document .
11,563
protected function generatePortals ( ) { foreach ( $ this -> xpath -> query ( '/x:webspace/x:portals/x:portal' ) as $ portalNode ) { $ portal = new Portal ( ) ; $ portal -> setName ( $ this -> xpath -> query ( 'x:name' , $ portalNode ) -> item ( 0 ) -> nodeValue ) ; $ portal -> setKey ( $ this -> xpath -> query ( 'x:key' , $ portalNode ) -> item ( 0 ) -> nodeValue ) ; $ this -> generatePortalLocalizations ( $ portalNode , $ portal ) ; $ this -> webspace -> addPortal ( $ portal ) ; $ portal -> setWebspace ( $ this -> webspace ) ; $ this -> generateEnvironments ( $ portalNode , $ portal ) ; } }
Generate all the portals for the webspace .
11,564
protected function generateTheme ( ) { $ nodes = $ this -> xpath -> query ( '/x:webspace/x:theme/x:key' ) ; if ( $ nodes -> length > 0 ) { return $ nodes -> item ( 0 ) -> nodeValue ; } $ nodes = $ this -> xpath -> query ( '/x:webspace/x:theme' ) ; if ( 0 === $ nodes -> length ) { return ; } return $ nodes -> item ( 0 ) -> nodeValue ; }
Generates the theme for the webspace .
11,565
protected function generateTemplates ( Webspace $ webspace ) { $ defaultErrorTemplates = 0 ; foreach ( $ this -> xpath -> query ( '/x:webspace/x:theme/x:error-templates/x:error-template' ) as $ errorTemplateNode ) { $ template = $ errorTemplateNode -> nodeValue ; if ( null !== ( $ codeNode = $ errorTemplateNode -> attributes -> getNamedItem ( 'code' ) ) ) { $ webspace -> addTemplate ( 'error-' . $ codeNode -> nodeValue , $ template ) ; } elseif ( null !== ( $ defaultNode = $ errorTemplateNode -> attributes -> getNamedItem ( 'default' ) ) ) { $ default = 'true' === $ defaultNode -> nodeValue ; if ( ! $ default ) { throw new InvalidDefaultErrorTemplateException ( $ template , $ this -> webspace -> getKey ( ) ) ; } ++ $ defaultErrorTemplates ; $ webspace -> addTemplate ( 'error' , $ template ) ; } else { throw new InvalidErrorTemplateException ( $ template , $ this -> webspace -> getKey ( ) ) ; } } if ( $ defaultErrorTemplates > 1 ) { throw new InvalidAmountOfDefaultErrorTemplateException ( $ this -> webspace -> getKey ( ) ) ; } return $ webspace ; }
Generates the available template types for the given webspace .
11,566
protected function generateDefaultTemplates ( Webspace $ webspace ) { $ expected = [ 'page' , 'home' ] ; foreach ( $ this -> xpath -> query ( '/x:webspace/x:theme/x:default-templates/x:default-template' ) as $ node ) { $ template = $ node -> nodeValue ; $ type = $ node -> attributes -> getNamedItem ( 'type' ) -> nodeValue ; $ webspace -> addDefaultTemplate ( $ type , $ template ) ; if ( 'homepage' === $ type ) { $ webspace -> addDefaultTemplate ( 'home' , $ template ) ; } } $ found = array_keys ( $ webspace -> getDefaultTemplates ( ) ) ; foreach ( $ expected as $ item ) { if ( ! in_array ( $ item , $ found ) ) { throw new ExpectedDefaultTemplatesNotFound ( $ this -> webspace -> getKey ( ) , $ expected , $ found ) ; } } return $ webspace ; }
Generates the default templates for the webspace .
11,567
protected function generateNavigation ( ) { $ contexts = [ ] ; foreach ( $ this -> xpath -> query ( '/x:webspace/x:navigation/x:contexts/x:context' ) as $ contextNode ) { $ contexts [ ] = new NavigationContext ( $ contextNode -> attributes -> getNamedItem ( 'key' ) -> nodeValue , $ this -> loadMeta ( 'x:meta/x:*' , $ contextNode ) ) ; } return new Navigation ( $ contexts ) ; }
Generates the availabel navigation contexts for the webspace .
11,568
protected function loadMeta ( $ path , \ DOMNode $ context = null ) { $ result = [ ] ; foreach ( $ this -> xpath -> query ( $ path , $ context ) as $ node ) { $ attribute = $ node -> tagName ; $ lang = $ this -> xpath -> query ( '@lang' , $ node ) -> item ( 0 ) -> nodeValue ; if ( ! isset ( $ result [ $ node -> tagName ] ) ) { $ result [ $ attribute ] = [ ] ; } $ result [ $ attribute ] [ $ lang ] = $ node -> textContent ; } return $ result ; }
Loads the meta information like a translatable title from the webspace .
11,569
protected function generateEnvironments ( \ DOMNode $ portalNode , Portal $ portal ) { foreach ( $ this -> xpath -> query ( 'x:environments/x:environment' , $ portalNode ) as $ environmentNode ) { $ environment = new Environment ( ) ; $ environment -> setType ( $ environmentNode -> attributes -> getNamedItem ( 'type' ) -> nodeValue ) ; $ this -> generateUrls ( $ environmentNode , $ environment ) ; $ this -> generateCustomUrls ( $ environmentNode , $ environment ) ; $ portal -> addEnvironment ( $ environment ) ; } }
Generates the definitions for the available environments for this webspace .
11,570
protected function generateUrls ( \ DOMNode $ environmentNode , Environment $ environment ) { foreach ( $ this -> xpath -> query ( 'x:urls/x:url' , $ environmentNode ) as $ urlNode ) { if ( ! $ this -> checkUrlNode ( $ urlNode ) ) { throw new InvalidUrlDefinitionException ( $ this -> webspace , $ urlNode -> nodeValue ) ; } $ url = new Url ( ) ; $ url -> setUrl ( rtrim ( $ urlNode -> nodeValue , '/' ) ) ; $ url -> setLanguage ( $ this -> getOptionalNodeAttribute ( $ urlNode , 'language' ) ) ; $ url -> setCountry ( $ this -> getOptionalNodeAttribute ( $ urlNode , 'country' ) ) ; $ url -> setSegment ( $ this -> getOptionalNodeAttribute ( $ urlNode , 'segment' ) ) ; $ url -> setRedirect ( $ this -> getOptionalNodeAttribute ( $ urlNode , 'redirect' ) ) ; $ url -> setMain ( $ this -> getOptionalNodeAttribute ( $ urlNode , 'main' , false ) ) ; $ environment -> addUrl ( $ url ) ; } }
Generates the URLs for the given environment .
11,571
protected function generateCustomUrls ( \ DOMNode $ environmentNode , Environment $ environment ) { foreach ( $ this -> xpath -> query ( 'x:custom-urls/x:custom-url' , $ environmentNode ) as $ urlNode ) { $ url = new CustomUrl ( ) ; $ url -> setUrl ( rtrim ( $ urlNode -> nodeValue , '/' ) ) ; if ( false === strpos ( $ url -> getUrl ( ) , '*' ) ) { throw new InvalidCustomUrlException ( $ this -> webspace , $ url -> getUrl ( ) ) ; } $ environment -> addCustomUrl ( $ url ) ; } }
Generates the custom URLs from the XML document .
11,572
protected function getOptionalNodeAttribute ( \ DOMNode $ node , $ name , $ default = null ) { $ attribute = $ node -> attributes -> getNamedItem ( $ name ) ; if ( $ attribute ) { return $ attribute -> nodeValue ; } return $ default ; }
Returns an optional value from the given node . The default value will be used if the node does not exist .
11,573
protected function checkUrlNode ( \ DOMNode $ urlNode ) { $ hasLocalization = ( null != $ urlNode -> attributes -> getNamedItem ( 'localization' ) ) || ( false !== strpos ( $ urlNode -> nodeValue , '{localization}' ) ) ; $ hasLanguage = ( null != $ urlNode -> attributes -> getNamedItem ( 'language' ) ) || ( false !== strpos ( $ urlNode -> nodeValue , '{language}' ) ) || $ hasLocalization ; $ hasSegment = ( 0 == count ( $ this -> webspace -> getSegments ( ) ) ) || ( null != $ urlNode -> attributes -> getNamedItem ( 'segment' ) ) || ( false !== strpos ( $ urlNode -> nodeValue , '{segment}' ) ) ; $ hasRedirect = ( null != $ urlNode -> attributes -> getNamedItem ( 'redirect' ) ) ; return ( $ hasLanguage && $ hasSegment ) || $ hasRedirect ; }
Checks if the urlNode is valid for this webspace .
11,574
protected function validateWebspaceDefaultLocalization ( ) { try { $ this -> validateDefaultLocalization ( $ this -> webspace -> getLocalizations ( ) ) ; } catch ( InvalidDefaultLocalizationException $ ex ) { throw new InvalidWebspaceDefaultLocalizationException ( $ this -> webspace ) ; } }
Validate default webspace localization .
11,575
protected function validateDefaultPortalLocalization ( ) { foreach ( $ this -> webspace -> getPortals ( ) as $ portal ) { try { if ( ! $ this -> validateDefaultLocalization ( $ portal -> getLocalizations ( ) ) ) { if ( ! $ this -> loadPortalLocalizationDefaultFromWebspace ( $ portal ) ) { throw new PortalDefaultLocalizationNotFoundException ( $ this -> webspace , $ portal ) ; } } } catch ( InvalidDefaultLocalizationException $ ex ) { throw new InvalidPortalDefaultLocalizationException ( $ this -> webspace , $ portal ) ; } } }
Validate portal localization .
11,576
protected function validateWebspaceDefaultSegment ( ) { $ segments = $ this -> webspace -> getSegments ( ) ; if ( $ segments ) { $ webspaceDefaultSegmentFound = false ; foreach ( $ segments as $ webspaceSegment ) { if ( $ webspaceSegment -> isDefault ( ) ) { if ( $ webspaceDefaultSegmentFound ) { throw new InvalidWebspaceDefaultSegmentException ( $ this -> webspace ) ; } $ webspaceDefaultSegmentFound = true ; } } if ( ! $ webspaceDefaultSegmentFound ) { throw new WebspaceDefaultSegmentNotFoundException ( $ this -> webspace ) ; } } }
Validate webspace default segment .
11,577
protected function validateDefaultLocalization ( $ localizations ) { $ result = false ; foreach ( $ localizations as $ localization ) { if ( $ localization -> isDefault ( ) ) { if ( $ result ) { throw new InvalidDefaultLocalizationException ( ) ; } $ result = true ; } } return $ result ; }
Returns true if there is one default localization .
11,578
private function getIdsQuery ( $ depth = 0 , $ filter = [ ] , $ sortBy = [ ] , CollectionInterface $ collection = null , $ select = 'collection.id' ) { $ queryBuilder = $ this -> createQueryBuilder ( 'collection' ) -> select ( $ select ) -> where ( 'collection.depth <= :depth' ) ; $ collectionDepth = null !== $ collection ? $ collection -> getDepth ( ) : 0 ; $ queryBuilder -> setParameter ( 'depth' , $ collectionDepth + $ depth ) ; if ( null !== $ collection ) { $ queryBuilder -> andWhere ( 'collection.lft BETWEEN :lft AND :rgt AND collection.id != :id' ) ; $ queryBuilder -> setParameter ( 'lft' , $ collection -> getLft ( ) ) ; $ queryBuilder -> setParameter ( 'rgt' , $ collection -> getRgt ( ) ) ; $ queryBuilder -> setParameter ( 'id' , $ collection -> getId ( ) ) ; } if ( array_key_exists ( 'search' , $ filter ) && null !== $ filter [ 'search' ] || array_key_exists ( 'locale' , $ filter ) || count ( $ sortBy ) > 0 ) { $ queryBuilder -> leftJoin ( 'collection.meta' , 'collectionMeta' ) ; $ queryBuilder -> leftJoin ( 'collection.defaultMeta' , 'defaultMeta' ) ; } if ( array_key_exists ( 'search' , $ filter ) && null !== $ filter [ 'search' ] ) { $ queryBuilder -> andWhere ( 'collectionMeta.title LIKE :search OR defaultMeta.locale != :locale' ) ; $ queryBuilder -> setParameter ( 'search' , '%' . $ filter [ 'search' ] . '%' ) ; } if ( array_key_exists ( 'locale' , $ filter ) ) { $ queryBuilder -> andWhere ( 'collectionMeta.locale = :locale OR defaultMeta.locale != :locale' ) ; $ queryBuilder -> setParameter ( 'locale' , $ filter [ 'locale' ] ) ; } if ( array_key_exists ( 'systemCollections' , $ filter ) && ! $ filter [ 'systemCollections' ] ) { $ queryBuilder -> leftJoin ( 'collection.type' , 'collectionType' ) ; $ queryBuilder -> andWhere ( 'collectionType.key != :type' ) ; $ queryBuilder -> setParameter ( 'type' , SystemCollectionManagerInterface :: COLLECTION_TYPE ) ; } if ( count ( $ sortBy ) > 0 ) { foreach ( $ sortBy as $ column => $ order ) { $ queryBuilder -> addOrderBy ( 'collectionMeta.' . $ column , ( 'asc' === strtolower ( $ order ) ? 'ASC' : 'DESC' ) ) ; } } $ queryBuilder -> addOrderBy ( 'collection.id' , 'ASC' ) ; if ( array_key_exists ( 'limit' , $ filter ) ) { $ queryBuilder -> setMaxResults ( $ filter [ 'limit' ] ) ; } if ( array_key_exists ( 'offset' , $ filter ) ) { $ queryBuilder -> setFirstResult ( $ filter [ 'offset' ] ) ; } return $ queryBuilder -> getQuery ( ) ; }
Returns the basic query which selects the ids of a collection for a given set of parameters .
11,579
public function refreshDocument ( RefreshEvent $ event ) { $ document = $ event -> getDocument ( ) ; $ node = $ this -> documentRegistry -> getNodeForDocument ( $ document ) ; $ locale = $ this -> documentRegistry -> getLocaleForDocument ( $ document ) ; $ node -> revert ( ) ; $ this -> rehydrateDocument ( $ document , $ node , $ locale ) ; }
Refreshes the document when the DocumentManager method for it is called .
11,580
public function refreshDocumentForDeleteDraft ( RemoveDraftEvent $ event ) { $ this -> rehydrateDocument ( $ event -> getDocument ( ) , $ event -> getNode ( ) , $ event -> getLocale ( ) ) ; }
Refreshes the document after a draft have been removed .
11,581
private function rehydrateDocument ( $ document , NodeInterface $ node , $ locale ) { $ hydrateEvent = new HydrateEvent ( $ node , $ locale , [ 'rehydrate' => true ] ) ; $ hydrateEvent -> setDocument ( $ document ) ; $ this -> eventDispatcher -> dispatch ( Events :: HYDRATE , $ hydrateEvent ) ; }
Rehydrates the given document from the given node for the given locale .
11,582
public function targetGroupAction ( Request $ request ) { $ currentTargetGroup = null ; if ( $ request -> headers -> has ( $ this -> targetGroupHeader ) ) { $ currentTargetGroup = $ this -> targetGroupRepository -> find ( $ request -> headers -> get ( $ this -> targetGroupHeader ) ) ; } $ targetGroup = $ this -> targetGroupEvaluator -> evaluate ( $ currentTargetGroup ? TargetGroupRuleInterface :: FREQUENCY_SESSION : TargetGroupRuleInterface :: FREQUENCY_VISITOR , $ currentTargetGroup ) ; $ response = new Response ( null , 200 , [ $ this -> targetGroupHeader => $ targetGroup ? $ targetGroup -> getId ( ) : 0 , ] ) ; return $ response ; }
Takes the request and evaluates a target group based on the request .
11,583
public function targetGroupHitAction ( ) { $ currentTargetGroup = $ this -> targetGroupRepository -> find ( $ this -> targetGroupStore -> getTargetGroupId ( true ) ) ; $ targetGroup = $ this -> targetGroupEvaluator -> evaluate ( TargetGroupRuleInterface :: FREQUENCY_HIT , $ currentTargetGroup ) ; $ response = new Response ( ) ; if ( $ targetGroup ) { $ this -> targetGroupStore -> updateTargetGroupId ( $ targetGroup -> getId ( ) ) ; } return $ response ; }
This end point is called by the injected code on the website to update the target group on every hit .
11,584
protected function updateConditionGroup ( ConditionGroupEntity $ conditionGroup , $ matchedEntry ) { if ( array_key_exists ( 'id' , $ matchedEntry ) && isset ( $ matchedEntry [ 'conditions' ] ) ) { $ conditionIds = [ ] ; foreach ( $ matchedEntry [ 'conditions' ] as $ conditionData ) { if ( array_key_exists ( 'id' , $ conditionData ) ) { $ conditionEntity = $ this -> conditionRepository -> findById ( $ conditionData [ 'id' ] ) ; if ( ! $ conditionEntity ) { throw new FilterDependencyNotFoundException ( self :: $ conditionEntityName , $ conditionData [ 'id' ] ) ; } if ( $ conditionEntity -> getConditionGroup ( ) -> getId ( ) !== $ conditionGroup -> getId ( ) ) { throw new ConditionGroupMismatchException ( $ matchedEntry [ 'id' ] ) ; } $ conditionIds [ ] = $ conditionEntity -> getId ( ) ; } else { $ conditionEntity = new ConditionEntity ( ) ; $ conditionEntity -> setConditionGroup ( $ conditionGroup ) ; $ conditionGroup -> addCondition ( $ conditionEntity ) ; $ this -> em -> persist ( $ conditionEntity ) ; $ conditionIds [ ] = $ conditionEntity -> getId ( ) ; } $ conditionEntity -> setField ( $ this -> getProperty ( $ conditionData , 'field' , $ conditionEntity -> getField ( ) ) ) ; $ conditionEntity -> setOperator ( $ this -> getProperty ( $ conditionData , 'operator' , $ conditionEntity -> getOperator ( ) ) ) ; $ conditionEntity -> setType ( $ this -> getProperty ( $ conditionData , 'type' , $ conditionEntity -> getType ( ) ) ) ; $ value = $ this -> getValueForCondition ( $ this -> getProperty ( $ conditionData , 'value' , $ conditionEntity -> getValue ( ) ) , $ conditionEntity -> getType ( ) ) ; $ conditionEntity -> setValue ( $ value ) ; } $ this -> removeNonExistentConditions ( $ conditionGroup , $ conditionIds ) ; } return true ; }
Updates the given condition group with the values from the given array .
11,585
protected function getValueForCondition ( $ value , $ type ) { if ( DataTypes :: DATETIME_TYPE === $ type && ! preg_match ( '/[A-Za-z]{3,}/' , $ value ) ) { return ( new \ DateTime ( $ value ) ) -> format ( \ DateTime :: ISO8601 ) ; } return $ value ; }
Parses the value for a condition - is mainly used for parsing values with type datetime but excludes relative values like - 1 week or now .
11,586
protected function addConditionGroup ( Filter $ filter , $ conditionGroupData ) { if ( array_key_exists ( 'id' , $ conditionGroupData ) ) { throw new EntityIdAlreadySetException ( self :: $ conditionGroupEntityName , $ conditionGroupData [ 'id' ] ) ; } elseif ( array_key_exists ( 'conditions' , $ conditionGroupData ) ) { $ conditionGroup = new ConditionGroupEntity ( ) ; $ conditionGroup -> setFilter ( $ filter -> getEntity ( ) ) ; foreach ( $ conditionGroupData [ 'conditions' ] as $ conditionData ) { if ( array_key_exists ( 'id' , $ conditionData ) ) { throw new EntityIdAlreadySetException ( self :: $ conditionEntityName , $ conditionData [ 'id' ] ) ; } elseif ( $ this -> isValidConditionData ( $ conditionData ) ) { $ condition = new ConditionEntity ( ) ; $ condition -> setType ( $ conditionData [ 'type' ] ) ; $ value = $ this -> getValueForCondition ( $ conditionData [ 'value' ] , $ conditionData [ 'type' ] ) ; $ condition -> setValue ( $ value ) ; $ condition -> setOperator ( $ conditionData [ 'operator' ] ) ; $ condition -> setField ( $ conditionData [ 'field' ] ) ; $ condition -> setConditionGroup ( $ conditionGroup ) ; $ conditionGroup -> addCondition ( $ condition ) ; $ conditionGroup -> setFilter ( $ filter -> getEntity ( ) ) ; $ this -> em -> persist ( $ condition ) ; } } $ filter -> getEntity ( ) -> addConditionGroup ( $ conditionGroup ) ; $ this -> em -> persist ( $ conditionGroup ) ; } return true ; }
Adds a condition group to the given filter .
11,587
protected function isValidConditionData ( $ data ) { if ( ! array_key_exists ( 'field' , $ data ) ) { throw new MissingConditionAttributeException ( 'field' ) ; } if ( ! array_key_exists ( 'operator' , $ data ) ) { throw new MissingConditionAttributeException ( 'operator' ) ; } if ( ! array_key_exists ( 'type' , $ data ) ) { throw new MissingConditionAttributeException ( 'type' ) ; } if ( ! array_key_exists ( 'value' , $ data ) ) { throw new MissingConditionAttributeException ( 'value' ) ; } return true ; }
Checks if the given data is correct for a condition .
11,588
public function getFeaturesForContext ( $ context ) { if ( $ this -> contextConfiguration && array_key_exists ( $ context , $ this -> contextConfiguration ) ) { return $ this -> contextConfiguration [ $ context ] [ 'features' ] ; } return ; }
Returns the configured features for a context .
11,589
protected function removeNonExistentConditions ( $ conditionGroup , $ conditionIds ) { foreach ( $ conditionGroup -> getConditions ( ) as $ condition ) { if ( $ condition -> getId ( ) && ! in_array ( $ condition -> getId ( ) , $ conditionIds ) ) { $ conditionGroup -> removeCondition ( $ condition ) ; $ this -> em -> remove ( $ condition ) ; } } }
Removes conditions from condition groups when they are not in the given array .
11,590
public function hasContext ( $ context ) { if ( $ this -> contextConfiguration && array_key_exists ( $ context , $ this -> contextConfiguration ) ) { return true ; } return false ; }
Checks if the context exists .
11,591
public function isFeatureEnabled ( $ context , $ feature ) { if ( $ this -> hasContext ( $ context ) && false !== array_search ( $ feature , $ this -> getFeaturesForContext ( $ context ) ) ) { return true ; } return false ; }
Checks if a feature is enabled for a context .
11,592
public function findFiltersForUserAndContext ( $ context , $ userId , $ locale ) { $ filters = $ this -> filterRepository -> findByUserAndContextAndLocale ( $ locale , $ context , $ userId ) ; array_walk ( $ filters , function ( & $ filter ) use ( $ locale ) { $ filter = new Filter ( $ filter , $ locale ) ; } ) ; return $ filters ; }
Finds all filters filtered by context and user and for the given locale .
11,593
private function buildData ( $ uploadedFile , $ data , $ user ) { if ( ! ( $ uploadedFile instanceof UploadedFile ) ) { throw new InvalidFileException ( 'Given uploaded file is not of instance UploadedFile' ) ; } $ this -> validator -> validate ( $ uploadedFile ) ; $ data [ 'storageOptions' ] = $ this -> storage -> save ( $ uploadedFile -> getPathname ( ) , $ this -> getNormalizedFileName ( $ uploadedFile -> getClientOriginalName ( ) ) ) ; $ data [ 'name' ] = $ uploadedFile -> getClientOriginalName ( ) ; $ data [ 'size' ] = $ uploadedFile -> getSize ( ) ; $ data [ 'mimeType' ] = $ uploadedFile -> getMimeType ( ) ; $ data [ 'properties' ] = $ this -> getProperties ( $ uploadedFile ) ; $ data [ 'type' ] = [ 'id' => $ this -> typeManager -> getMediaType ( $ uploadedFile -> getMimeType ( ) ) , ] ; return $ this -> createMedia ( $ data , $ user ) ; }
Prepares data .
11,594
protected function createMedia ( $ data , $ user ) { $ mediaEntity = $ this -> mediaRepository -> createNew ( ) ; $ mediaEntity -> setCreator ( $ user ) ; $ mediaEntity -> setChanger ( $ user ) ; $ file = new File ( ) ; $ file -> setCreator ( $ user ) ; $ file -> setChanger ( $ user ) ; $ file -> setVersion ( 1 ) ; $ file -> setMedia ( $ mediaEntity ) ; $ fileVersion = new FileVersion ( ) ; $ fileVersion -> setCreator ( $ user ) ; $ fileVersion -> setChanger ( $ user ) ; $ fileVersion -> setVersion ( 1 ) ; $ fileVersion -> setFile ( $ file ) ; $ file -> addFileVersion ( $ fileVersion ) ; $ mediaEntity -> addFile ( $ file ) ; $ media = new Media ( $ mediaEntity , $ data [ 'locale' ] , null ) ; $ media = $ this -> setDataToMedia ( $ media , $ data , $ user ) ; $ fileVersion -> setDefaultMeta ( $ fileVersion -> getMeta ( ) -> first ( ) ) ; $ mediaEntity = $ media -> getEntity ( ) ; $ this -> em -> persist ( $ mediaEntity ) ; $ this -> em -> flush ( ) ; return $ media ; }
Create a new media .
11,595
protected function getCurrentUser ( ) { if ( ! $ this -> tokenStorage ) { return ; } if ( ! $ this -> tokenStorage -> getToken ( ) ) { return ; } $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; if ( $ user instanceof UserInterface ) { return $ user ; } return ; }
Returns current user or null if no user is loggedin .
11,596
private function getNormalizedFileName ( $ originalFileName ) { if ( false !== strpos ( $ originalFileName , '.' ) ) { $ pathParts = pathinfo ( $ originalFileName ) ; $ fileName = $ this -> pathCleaner -> cleanup ( $ pathParts [ 'filename' ] ) ; $ fileName .= '.' . $ pathParts [ 'extension' ] ; } else { $ fileName = $ this -> pathCleaner -> cleanup ( $ originalFileName ) ; } return $ fileName ; }
Returns file name without special characters and preserves file extension .
11,597
public function toArray ( ) { $ res = [ ] ; foreach ( $ this -> locations as $ location ) { $ res [ ] = $ location -> toArray ( ) ; } return $ res ; }
Return an array representation of the response .
11,598
public function initialize ( OutputInterface $ output = null , $ purge = false ) { $ output = $ output ? : new NullOutput ( ) ; arsort ( $ this -> initializerMap ) ; foreach ( array_keys ( $ this -> initializerMap ) as $ initializerId ) { $ output -> writeln ( sprintf ( '<comment>%s</>' , $ initializerId ) ) ; $ initializer = $ this -> container -> get ( $ initializerId ) ; $ initializer -> initialize ( $ output , $ purge ) ; } $ output -> write ( PHP_EOL ) ; $ output -> writeln ( '<comment>*</> Legend: [+] Added [*] Updated [-] Purged [ ] No change' ) ; }
Initialize the content repository optionally purging it before - hand .
11,599
public function getWebspaceCollection ( ) { if ( null === $ this -> webspaceCollection ) { $ class = $ this -> options [ 'cache_class' ] ; $ cache = new ConfigCache ( $ this -> options [ 'cache_dir' ] . '/' . $ class . '.php' , $ this -> options [ 'debug' ] ) ; if ( ! $ cache -> isFresh ( ) ) { $ webspaceCollectionBuilder = new WebspaceCollectionBuilder ( $ this -> loader , $ this -> urlReplacer , $ this -> options [ 'config_dir' ] ) ; $ webspaceCollection = $ webspaceCollectionBuilder -> build ( ) ; $ dumper = new PhpWebspaceCollectionDumper ( $ webspaceCollection ) ; $ cache -> write ( $ dumper -> dump ( [ 'cache_class' => $ class , 'base_class' => $ this -> options [ 'base_class' ] , ] ) , $ webspaceCollection -> getResources ( ) ) ; } require_once $ cache -> getPath ( ) ; $ this -> webspaceCollection = new $ class ( ) ; } return $ this -> webspaceCollection ; }
Returns all the webspaces managed by this specific instance .