idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
10,100
public static function add ( $ btsHandle , $ btsName , $ pkg = false ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ pkgID = ( int ) ( is_object ( $ pkg ) ? $ pkg -> getPackageID ( ) : $ pkg ) ; $ displayOrder = $ db -> fetchColumn ( 'select max(btsDisplayOrder) from BlockTypeSets' ) ; if ( $ displayOrder === null ) { $ displayOrder = 0 ; } else { ++ $ displayOrder ; } $ db -> insert ( 'BlockTypeSets' , [ 'btsHandle' => ( string ) $ btsHandle , 'btsName' => ( string ) $ btsName , 'pkgID' => $ pkgID , ] ) ; $ id = $ db -> lastInsertId ( ) ; $ bs = static :: getByID ( $ id ) ; return $ bs ; }
Create a new block type set .
10,101
public static function exportList ( $ xml ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ bxml = $ xml -> addChild ( 'blocktypesets' ) ; $ rs = $ db -> executeQuery ( 'select btsID from BlockTypeSets order by btsID asc' ) ; while ( ( $ btsID = $ rs -> fetchColumn ( ) ) !== false ) { $ bts = static :: getByID ( $ btsID ) ; $ bts -> export ( $ bxml ) ; } }
Export all the block type sets to a SimpleXMLElement element .
10,102
public static function getUnassignedBlockTypes ( $ includeInternalBlockTypes = false ) { $ result = [ ] ; $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ rs = $ db -> executeQuery ( <<<EOTselect BlockTypes.btIDfrom BlockTypesleft join BlockTypeSetBlockTypes on BlockTypes.btID = BlockTypeSetBlockTypes.btIDleft join BlockTypeSets on BlockTypeSetBlockTypes.btsID = BlockTypeSets.btsIDwhere BlockTypeSets.btsID is nullorder by BlockTypes.btDisplayOrder ascEOT ) ; while ( ( $ btID = $ rs -> fetchColumn ( ) ) !== false ) { $ bt = BlockType :: getByID ( $ btID ) ; if ( $ bt !== null ) { if ( $ includeInternalBlockTypes || ! $ bt -> isBlockTypeInternal ( ) ) { $ result [ ] = $ bt ; } } } return $ result ; }
Get the list of block types that don t belong to any block type set .
10,103
public function getPackageHandle ( ) { $ pkgID = $ this -> getPackageID ( ) ; return empty ( $ pkgID ) ? false : PackageList :: getHandle ( $ pkgID ) ; }
Get the handle of the package that defined this set .
10,104
public function updateBlockTypeSetName ( $ btsName ) { $ btsName = ( string ) $ btsName ; $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ db -> update ( 'BlockTypeSets' , [ 'btsName' => $ btsName ] , [ 'btsID' => $ this -> getBlockTypeSetID ( ) ] ) ; $ this -> btsName = $ btsName ; }
Update the name of this set .
10,105
public function updateBlockTypeSetHandle ( $ btsHandle ) { $ btsHandle = ( string ) $ btsHandle ; $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ db -> update ( 'BlockTypeSets' , [ 'btsHandle' => $ btsHandle ] , [ 'btsID' => $ this -> getBlockTypeSetID ( ) ] ) ; $ this -> btsHandle = $ btsHandle ; }
Update the handle of this set .
10,106
public function updateBlockTypeSetDisplayOrder ( $ displayOrder ) { $ displayOrder = ( string ) $ displayOrder ; $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ db -> update ( 'BlockTypeSets' , [ 'btsDisplayOrder' => $ displayOrder ] , [ 'btsID' => $ this -> getBlockTypeSetID ( ) ] ) ; }
Update the display order of this set .
10,107
public function addBlockType ( BlockTypeEntity $ bt ) { if ( ! $ this -> contains ( $ bt ) ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ displayOrder = $ db -> fetchColumn ( 'select max(displayOrder) from BlockTypeSetBlockTypes where btsID = ?' , [ $ this -> getBlockTypeSetID ( ) ] ) ; if ( $ displayOrder === null ) { $ displayOrder = 0 ; } else { ++ $ displayOrder ; } $ db -> insert ( 'BlockTypeSetBlockTypes' , [ 'btsID' => $ this -> getBlockTypeSetID ( ) , 'btID' => $ bt -> getBlockTypeID ( ) , 'displayOrder' => $ displayOrder , ] ) ; } }
Associate a block type to this set .
10,108
public function setBlockTypeDisplayOrder ( BlockTypeEntity $ bt , $ displayOrder ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ db -> update ( 'BlockTypeSetBlockTypes' , [ 'displayOrder' => $ displayOrder ] , [ 'btID' => $ bt -> getBlockTypeID ( ) , 'btsID' => $ this -> getBlockTypeSetID ( ) ] ) ; }
Update the display order of a block type contained in this set .
10,109
public function clearBlockTypes ( ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ db -> delete ( 'BlockTypeSetBlockTypes' , [ 'btsID' => $ this -> getBlockTypeSetID ( ) ] ) ; }
Disassociate all the block types currently associated to this set .
10,110
public function deleteKey ( $ bt ) { $ btID = ( int ) ( is_object ( $ bt ) ? $ bt -> getBlockTypeID ( ) : $ bt ) ; if ( $ btID !== 0 ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ db -> delete ( 'BlockTypeSetBlockTypes' , [ 'btsID' => $ this -> getBlockTypeSetID ( ) , 'btID' => $ btID ] ) ; $ this -> rescanDisplayOrder ( ) ; } }
Dissociate a specific block type currently associated to this set .
10,111
public function export ( $ axml ) { $ bset = $ axml -> addChild ( 'blocktypeset' ) ; $ bset -> addAttribute ( 'handle' , $ this -> getBlockTypeSetHandle ( ) ) ; $ bset -> addAttribute ( 'name' , $ this -> getBlockTypeSetName ( ) ) ; $ bset -> addAttribute ( 'package' , $ this -> getPackageHandle ( ) ) ; $ types = $ this -> getBlockTypes ( ) ; foreach ( $ types as $ bt ) { $ typenode = $ bset -> addChild ( 'blocktype' ) ; $ typenode -> addAttribute ( 'handle' , $ bt -> getBlockTypeHandle ( ) ) ; } return $ bset ; }
Export this set to a SimpleXMLElement element .
10,112
public function getBlockTypes ( ) { $ result = [ ] ; $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ rs = $ db -> executeQuery ( 'select btID from BlockTypeSetBlockTypes where btsID = ? order by displayOrder asc' , [ $ this -> getBlockTypeSetID ( ) ] ) ; while ( ( $ btID = $ rs -> fetchColumn ( ) ) !== false ) { $ bt = BlockType :: getByID ( $ btID ) ; if ( $ bt !== null ) { $ result [ ] = $ bt ; } } return $ result ; }
Get the list of block types associated to this set .
10,113
public function contains ( $ bt ) { $ result = false ; $ btID = ( int ) ( is_object ( $ bt ) ? $ bt -> getBlockTypeID ( ) : $ bt ) ; if ( $ btID !== 0 ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ result = $ db -> fetchColumn ( 'select btID from BlockTypeSetBlockTypes where btsID = ? and btID = ?' , [ $ this -> getBlockTypeSetID ( ) , $ btID ] ) !== false ; } return $ result ; }
Does this set contain a block type?
10,114
public function delete ( ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ db -> delete ( 'BlockTypeSetBlockTypes' , [ 'btsID' => $ this -> getBlockTypeSetID ( ) ] ) ; $ db -> delete ( 'BlockTypeSets' , [ 'btsID' => $ this -> getBlockTypeSetID ( ) ] ) ; }
Delete this set .
10,115
protected function rescanDisplayOrder ( ) { $ displayOrder = 0 ; $ btsID = $ this -> getBlockTypeSetID ( ) ; $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ rs = $ db -> executeQuery ( 'select btID from BlockTypeSetBlockTypes where btsID = ? order by displayOrder asc' , [ $ btsID ] ) ; while ( ( $ btID = $ rs -> fetchColumn ( ) ) !== false ) { $ db -> update ( 'BlockTypeSetBlockTypes' , [ 'displayOrder' => $ displayOrder , ] , [ 'btID' => $ btID , 'btsID' => $ btsID , ] ) ; ++ $ displayOrder ; } }
Regenereate the display order values of the block types associated to this set .
10,116
protected function getDefaultMessageFilter ( ) { $ filter = 'all' ; $ db = \ Database :: get ( ) ; $ count = $ db -> GetOne ( 'select count(cpa.paID) from ConversationPermissionAssignments cpa inner join PermissionAccess pa on cpa.paID = pa.paID inner join ConversationPermissionAddMessageAccessList cpl on pa.paID = cpl.paID where paIsInUse = 1 and permission = "U"' ) ; if ( $ count > 0 ) { $ filter = 'unapproved' ; } return $ filter ; }
Returns default message filter for search interface . We default to all UNLESS we have at least one access entity that publishes its messages and has them be unapproved . If that s the case then we default to unapproved .
10,117
public function getPageCanonicalURL ( $ page , $ querystring = null ) { $ result = null ; if ( $ page ) { if ( $ this -> valn -> integer ( $ page , 1 ) ) { $ page = Page :: getByID ( $ page ) ; } if ( $ page instanceof Page && ! $ page -> isError ( ) ) { $ cID = $ page -> getCollectionID ( ) ; $ originalCID = $ page -> getCollectionPointerOriginalID ( ) ; if ( ! empty ( $ originalCID ) && $ originalCID != $ cID ) { $ result = $ this -> getPageCanonicalURL ( $ cID , $ querystring ) ; } else { $ result = $ this -> resolver -> resolve ( [ $ page ] ) ; $ query = null ; if ( $ querystring instanceof Query ) { $ query = clone $ querystring ; } elseif ( $ querystring instanceof Request ) { $ query = new Query ( $ querystring -> query -> all ( ) ) ; } elseif ( $ querystring instanceof ParameterBag ) { $ query = new Query ( $ querystring -> all ( ) ) ; } elseif ( is_array ( $ querystring ) ) { $ query = new Query ( $ querystring ) ; } elseif ( is_string ( $ querystring ) ) { if ( $ querystring !== '' ) { $ query = new Query ( $ querystring ) ; } } if ( $ query !== null && $ query -> count ( ) > 0 ) { foreach ( $ this -> excludedQuerystringParameters as $ qp ) { $ query -> offsetUnset ( $ qp ) ; } $ result = $ result -> setQuery ( $ query ) ; } } } } return $ result ; }
Generate the canonical URL of a page .
10,118
public function getStaticValues ( array $ cells ) { $ result = [ ] ; foreach ( $ this -> fieldsMap as $ cellIndex => $ info ) { if ( $ info [ 'kind' ] === 'staticHeader' ) { $ fieldName = $ info [ 'staticHeaderName' ] ; $ result [ $ fieldName ] = isset ( $ cells [ $ cellIndex ] ) ? $ cells [ $ cellIndex ] : '' ; } } return $ result ; }
Get the values of the cells associated to the static headers .
10,119
public function getAttributesValues ( array $ cells ) { $ result = [ ] ; foreach ( $ this -> fieldsMap as $ cellIndex => $ info ) { switch ( $ info [ 'kind' ] ) { case 'singleAttributeHeader' : $ attributeIndex = $ info [ 'attributeIndex' ] ; $ result [ $ attributeIndex ] = isset ( $ cells [ $ cellIndex ] ) ? $ cells [ $ cellIndex ] : '' ; break ; case 'multipleAttributeHeader' : $ attributeIndex = $ info [ 'attributeIndex' ] ; $ attributeSubHeader = $ info [ 'attributeSubHeader' ] ; $ value = isset ( $ cells [ $ cellIndex ] ) ? $ cells [ $ cellIndex ] : '' ; if ( isset ( $ result [ $ attributeIndex ] ) ) { $ result [ $ attributeIndex ] [ $ attributeSubHeader ] = $ value ; } else { $ result [ $ attributeIndex ] = [ $ attributeSubHeader => $ value ] ; } break ; } } return $ result ; }
Get the values of the cells associated to the attributes .
10,120
public function getLevelIcon ( ) { switch ( $ this -> getLevel ( ) ) { case Monolog :: EMERGENCY : return '<i class="text-danger fa fa-fire launch-tooltip" title="' . $ this -> getLevelDisplayName ( ) . '"></i>' ; case Monolog :: CRITICAL : case Monolog :: ALERT : return '<i class="text-danger fa fa-exclamation-circle launch-tooltip" title="' . $ this -> getLevelDisplayName ( ) . '"></i>' ; case Monolog :: ERROR : case Monolog :: WARNING : return '<i class="text-warning fa fa-warning launch-tooltip" title="' . $ this -> getLevelDisplayName ( ) . '"></i>' ; case Monolog :: NOTICE : return '<i class="fa fa-exclamation launch-tooltip" title="' . $ this -> getLevelDisplayName ( ) . '"></i>' ; case Monolog :: INFO : return '<i class="text-info fa fa-info-circle launch-tooltip" title="' . $ this -> getLevelDisplayName ( ) . '"></i>' ; case Monolog :: DEBUG : return '<i class="text-info fa fa-cog launch-tooltip" title="' . $ this -> getLevelDisplayName ( ) . '"></i>' ; } }
Gets the HTML code for the icon of the logging level .
10,121
public function getUserObject ( ) { if ( $ this -> getUserID ( ) ) { $ u = User :: getByUserID ( $ this -> getUserID ( ) ) ; if ( is_object ( $ u ) ) { return $ u ; } } }
Gets the user object of the user that caused the log .
10,122
public function getDisplayTimestamp ( ) { $ app = Application :: getFacadeApplication ( ) ; $ dh = $ app -> make ( 'helper/date' ) ; return $ dh -> formatDateTime ( $ this -> time , true , true ) ; }
Gets the formatted time of the log timestamp .
10,123
public static function getByID ( $ logID ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( 'database' ) -> connection ( ) ; $ row = $ db -> fetchAssoc ( 'select * from Logs where logID = ?' , [ $ logID ] ) ; if ( $ row ) { $ obj = new static ( ) ; $ obj = array_to_object ( $ obj , $ row ) ; return $ obj ; } }
Gets the log object from its id .
10,124
public function delete ( ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( 'database' ) -> connection ( ) ; $ logID = $ this -> getID ( ) ; if ( ! empty ( $ logID ) ) { $ db -> delete ( 'Logs' , [ 'logID' => $ logID ] ) ; } }
Deletes the log entry .
10,125
public function hasFiles ( ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( 'database' ) ; $ fIDs = $ db -> fetchColumn ( 'SELECT fID FROM Files WHERE fslID = ?' , [ $ this -> getID ( ) ] ) ; return ( ! empty ( $ fIDs ) ) ; }
Check if the storage location contains files
10,126
protected function attemptAuthentication ( ) { $ extractor = $ this -> getExtractor ( ) ; if ( ! $ this -> isValid ( ) ) { throw new Exception ( 'Invalid account, user cannot be logged in.' ) ; } $ user_id = $ this -> getBoundUserID ( $ extractor -> getUniqueId ( ) ) ; if ( $ user_id && $ user_id > 0 ) { $ user = User :: loginByUserID ( $ user_id ) ; if ( $ user && ! $ user -> isError ( ) ) { return $ user ; } } if ( $ extractor -> supportsEmail ( ) && $ user = \ UserInfo :: getByEmail ( $ extractor -> getEmail ( ) ) ) { if ( $ user && ! $ user -> isError ( ) ) { throw new Exception ( 'A user account already exists for this email, please log in and attach from your account page.' ) ; } } if ( $ this -> supportsRegistration ( ) ) { if ( $ extractor -> getEmail ( ) === null || empty ( $ extractor -> getEmail ( ) ) ) { $ flashbag = $ this -> app -> make ( 'session' ) -> getFlashBag ( ) ; if ( $ this -> supportsFullName ( ) ) { $ flashbag -> set ( 'fullName' , $ this -> getFullName ( ) ) ; } else { $ flashbag -> set ( 'firstName' , $ this -> getFirstName ( ) ) ; $ flashbag -> set ( 'lastName' , $ this -> getLastName ( ) ) ; } $ flashbag -> set ( 'username' , $ this -> getUsername ( ) ) ; $ flashbag -> set ( 'token' , $ this -> getToken ( ) ) ; $ response = \ Redirect :: to ( '/login/callback/' . $ this -> getHandle ( ) . '/handle_register/' , id ( new Token ( ) ) -> generate ( $ this -> getHandle ( ) . '_register' ) ) ; $ response -> send ( ) ; exit ; } else { $ user = $ this -> createUser ( ) ; return $ user ; } } return null ; }
We now check if the user allows access to email address as twitter does not provide this and users can deny access to on facebook ) .
10,127
public function getBindingForUser ( $ user ) { $ result = null ; if ( is_object ( $ user ) ) { $ userID = $ user -> getUserID ( ) ; } else { $ userID = ( int ) $ user ; } if ( $ userID ) { $ db = $ this -> app -> make ( Connection :: class ) ; $ qb = $ db -> createQueryBuilder ( ) ; $ qb -> select ( 'oum.binding' ) -> from ( 'OauthUserMap' , 'oum' ) -> where ( $ qb -> expr ( ) -> eq ( 'oum.user_id' , ':user_id' ) ) -> setParameter ( 'user_id' , $ userID ) -> andWhere ( $ qb -> expr ( ) -> eq ( 'oum.namespace' , ':namespace' ) ) -> setParameter ( 'namespace' , $ this -> getHandle ( ) ) -> setMaxResults ( 1 ) ; $ rs = $ qb -> execute ( ) ; $ row = $ rs -> fetch ( ) ; $ rs -> closeCursor ( ) ; if ( $ row !== false ) { $ result = array_pop ( $ row ) ; } } return $ result ; }
Get the binding associated to a specific user .
10,128
public function authorize ( ) { $ response = new Response ( ) ; try { $ request = $ this -> getAuthorizationRequest ( ) ; $ step = $ this -> determineStep ( $ request ) ; if ( $ step === self :: STEP_LOGIN ) { if ( ! $ this -> user ) { return $ this -> handleLogin ( $ request ) ; } $ userEntity = $ this -> entityManager -> find ( User :: class , $ this -> user -> getUserID ( ) ) ; $ request -> setUser ( $ userEntity ) ; $ this -> storeRequest ( $ request ) ; $ step = $ this -> determineStep ( $ request ) ; } if ( $ step === self :: STEP_AUTHORIZE_CLIENT ) { if ( $ this -> getConsentType ( $ request ) !== Client :: CONSENT_NONE ) { return $ this -> handleAuthorizeClient ( $ request ) ; } $ request -> setAuthorizationApproved ( true ) ; $ this -> storeRequest ( $ request ) ; } $ this -> clearRequest ( $ request ) ; return $ this -> oauthServer -> completeAuthorizationRequest ( $ request , $ response ) ; } catch ( OAuthServerException $ exception ) { return $ exception -> generateHttpResponse ( $ response ) ; } catch ( \ Exception $ exception ) { $ body = new LazyOpenStream ( 'php://temp' , 'r+' ) ; $ body -> write ( $ exception -> getMessage ( ) ) ; return $ response -> withStatus ( 500 ) -> withBody ( $ body ) ; } }
Route handler that deals with authorization
10,129
public function handleLogin ( AuthorizationRequest $ request ) { $ error = new ErrorList ( ) ; $ emailLogin = $ this -> config -> get ( 'concrete.user.registration.email_registration' ) ; while ( $ this -> request -> getMethod ( ) === 'POST' ) { if ( ! $ this -> token -> validate ( 'oauth_login_' . $ request -> getClient ( ) -> getClientKey ( ) ) ) { $ error -> add ( $ this -> token -> getErrorMessage ( ) ) ; break ; } $ query = $ this -> request -> getParsedBody ( ) ; $ user = array_get ( $ query , 'uName' ) ; $ password = array_get ( $ query , 'uPassword' ) ; $ userRepository = $ this -> entityManager -> getRepository ( User :: class ) ; $ user = $ userRepository -> findOneBy ( [ $ emailLogin ? 'uEmail' : 'uName' => $ user ] ) ; if ( $ user && $ user -> getUserID ( ) && password_verify ( $ password , $ user -> getUserPassword ( ) ) ) { $ userInfo = $ this -> entityManager -> find ( User :: class , $ user -> getUserID ( ) ) ; $ request -> setUser ( $ userInfo ) ; $ this -> storeRequest ( $ request ) ; return new \ RedirectResponse ( $ this -> request -> getUri ( ) ) ; } else { $ error -> add ( t ( 'Invalid username or password.' ) ) ; } break ; } $ contents = $ this -> createLoginView ( [ 'error' => $ error , 'auth' => $ request , 'request' => $ this -> request , 'client' => $ request -> getClient ( ) , 'emailLogin' => $ emailLogin ] ) ; return new \ Concrete \ Core \ Http \ Response ( $ contents -> render ( ) ) ; }
Handle the login portion of an authorization request This method renders a view for login that handles either email or username based login
10,130
public function handleAuthorizeClient ( AuthorizationRequest $ request ) { $ error = new ErrorList ( ) ; $ client = $ request -> getClient ( ) ; while ( $ this -> request -> getMethod ( ) === 'POST' ) { if ( ! $ this -> token -> validate ( 'oauth_authorize_' . $ client -> getClientKey ( ) ) ) { $ error -> add ( $ this -> token -> getErrorMessage ( ) ) ; break ; } $ query = $ this -> request -> getParsedBody ( ) ; $ authorized = array_get ( $ query , 'authorize_client' ) ; $ consentType = $ this -> getConsentType ( $ request ) ; if ( $ consentType === Client :: CONSENT_NONE || $ authorized ) { $ request -> setAuthorizationApproved ( true ) ; $ this -> storeRequest ( $ request ) ; return new \ RedirectResponse ( $ this -> request -> getUri ( ) ) ; } break ; } $ contents = $ this -> createLoginView ( [ 'error' => $ error , 'auth' => $ request , 'request' => $ this -> request , 'client' => $ request -> getClient ( ) , 'authorize' => true , ] ) ; return new \ Concrete \ Core \ Http \ Response ( $ contents -> render ( ) ) ; }
Handle the scope authorization portion of an authorization request This method renders a view that outputs a list of scopes and asks the user to verify that they want to give the client the access that is being requested .
10,131
private function pruneTokens ( ) { $ now = new \ DateTime ( 'now' ) ; $ qb = $ this -> entityManager -> createQueryBuilder ( ) ; $ items = $ qb -> select ( 'token' ) -> from ( AccessToken :: class , 'token' ) -> where ( $ qb -> expr ( ) -> lt ( 'token.expiryDateTime' , ':now' ) ) -> getQuery ( ) -> execute ( [ ':now' => $ now ] ) ; $ this -> pruneResults ( $ items ) ; $ qb = $ this -> entityManager -> createQueryBuilder ( ) ; $ items = $ qb -> select ( 'token' ) -> from ( AccessToken :: class , 'token' ) -> where ( $ qb -> expr ( ) -> lt ( 'token.expiryDateTime' , ':now' ) ) -> getQuery ( ) -> execute ( [ ':now' => $ now ] ) ; $ this -> pruneResults ( $ items ) ; $ qb = $ this -> entityManager -> createQueryBuilder ( ) ; $ qb -> delete ( AuthCode :: class , 'token' ) -> where ( $ qb -> expr ( ) -> lt ( 'token.expiryDateTime' , ':now' ) ) -> getQuery ( ) -> execute ( [ ':now' => $ now ] ) ; }
Prune old authentication tokens
10,132
private function pruneResults ( $ results ) { $ buffer = [ ] ; foreach ( $ results as $ item ) { $ buffer [ ] = $ item ; if ( count ( $ buffer ) > 50 ) { $ this -> clearTokenBuffer ( $ buffer ) ; $ buffer = [ ] ; } } $ this -> clearTokenBuffer ( $ buffer ) ; }
Loop over a list of results and prune them
10,133
private function clearTokenBuffer ( array $ buffer ) { foreach ( $ buffer as $ bufferItem ) { if ( $ bufferItem instanceof AccessToken ) { $ refreshToken = $ this -> entityManager -> getRepository ( RefreshToken :: class ) -> findOneByAccessToken ( $ bufferItem ) ; if ( $ refreshToken ) { $ this -> entityManager -> remove ( $ refreshToken ) ; } } if ( $ bufferItem instanceof RefreshToken ) { $ accessToken = $ bufferItem -> getAccessToken ( ) ; if ( $ accessToken ) { $ this -> entityManager -> remove ( $ accessToken ) ; } } $ this -> entityManager -> remove ( $ bufferItem ) ; } $ this -> entityManager -> flush ( ) ; }
Remove items in a buffer from the entity manager
10,134
private function getConsentType ( AuthorizationRequest $ request ) { $ client = $ request -> getClient ( ) ; return $ client instanceof Client ? $ client -> getConsentType ( ) : Client :: CONSENT_SIMPLE ; }
Get the consent type associated with the current request
10,135
private function storeRequest ( AuthorizationRequest $ request ) { $ data = [ 'user' => $ request -> getUser ( ) ? $ request -> getUser ( ) -> getIdentifier ( ) : null , 'client' => $ request -> getClient ( ) -> getIdentifier ( ) , 'challenge' => $ request -> getCodeChallenge ( ) , 'challenge_method' => $ request -> getCodeChallengeMethod ( ) , 'grant_type' => $ request -> getGrantTypeId ( ) , 'redirect' => $ request -> getRedirectUri ( ) , 'scopes' => $ request -> getScopes ( ) , 'state' => $ request -> getState ( ) , 'approved' => ( bool ) $ request -> isAuthorizationApproved ( ) ] ; $ client = $ request -> getClient ( ) ; $ clientId = $ client -> getClientKey ( ) ; $ this -> session -> set ( "authn_request.$clientId" , $ data ) ; }
Store a request against session
10,136
private function restoreRequest ( array $ data ) { if ( ! $ data ) { return null ; } $ scopeData = ( array ) array_get ( $ data , 'scopes' , [ ] ) ; $ scopes = array_filter ( array_map ( [ $ this , 'inflateType' ] , $ scopeData ) ) ; $ user = $ this -> inflateType ( array_get ( $ data , 'user' ) , User :: class ) ; $ client = $ this -> inflateType ( array_get ( $ data , 'client' ) , Client :: class ) ; if ( ! $ user || ! $ client || count ( $ scopes ) !== count ( $ scopeData ) ) { return null ; } $ request = new AuthorizationRequest ( ) ; $ request -> setUser ( $ user ) ; $ request -> setClient ( $ client ) ; $ request -> setAuthorizationApproved ( ( bool ) array_get ( $ data , 'approved' , false ) ) ; $ request -> setCodeChallenge ( array_get ( $ data , 'challenge' , '' ) ) ; $ request -> setCodeChallengeMethod ( array_get ( $ data , 'challenge_method' , '' ) ) ; $ request -> setGrantTypeId ( array_get ( $ data , 'grant_type' ) ) ; $ request -> setState ( array_get ( $ data , 'state' ) ) ; $ request -> setScopes ( $ scopes ) ; $ request -> setRedirectUri ( array_get ( $ data , 'redirect' ) ) ; return $ request ; }
Restore a real request from the passed data
10,137
private function clearRequest ( AuthorizationRequest $ request ) { $ client = $ request -> getClient ( ) ; $ clientId = $ client -> getClientKey ( ) ; $ this -> session -> remove ( "authn_request.$clientId" ) ; }
Remove all session data related to this flow
10,138
private function inflateType ( $ identifier , $ type = Scope :: class ) { if ( $ identifier === null ) { return null ; } return $ this -> entityManager -> find ( $ type , $ identifier ) ; }
Inflate an identifier into a specific type
10,139
private function determineStep ( AuthorizationRequest $ request ) { if ( ! $ request -> getUser ( ) ) { return self :: STEP_LOGIN ; } if ( ! $ request -> isAuthorizationApproved ( ) ) { return self :: STEP_AUTHORIZE_CLIENT ; } return self :: STEP_COMPLETE ; }
Figure out what step we should be rendering based on the active authorization request This method should handle verifying authorization and login
10,140
private function createLoginView ( array $ data ) { $ consentType = $ this -> getConsentType ( $ this -> getAuthorizationRequest ( ) ) ; switch ( $ consentType ) { case Client :: CONSENT_NONE : break ; case Client :: CONSENT_SIMPLE : default : $ data [ 'consentView' ] = new View ( '/oauth/consent/simple' ) ; break ; } $ contents = new View ( '/oauth/authorize' ) ; $ contents -> setViewTheme ( 'concrete' ) ; $ contents -> setViewTemplate ( 'background_image.php' ) ; $ contents -> addScopeItems ( $ data ) ; return $ contents ; }
Create a new authorize login view with the given data in scope
10,141
public function activate ( ) { $ db = Loader :: db ( ) ; self :: deactivateAll ( ) ; $ db -> Execute ( 'update SystemAntispamLibraries set saslIsActive = 1 where saslHandle = ?' , array ( $ this -> saslHandle ) ) ; }
Activate an Antispam library .
10,142
public function has ( $ name ) { if ( in_array ( $ name , $ this -> responseCookies -> getClearedCookies ( ) , true ) ) { return false ; } return $ this -> request -> cookies -> has ( $ name ) || $ this -> responseCookies -> hasCookie ( $ name ) ; }
Does a cookie exist in the request or response cookies?
10,143
public static function getByID ( $ gID ) { $ db = Database :: connection ( ) ; $ g = CacheLocal :: getEntry ( 'group' , $ gID ) ; if ( is_object ( $ g ) ) { return $ g ; } $ row = $ db -> fetchAssoc ( 'select * from ' . $ db -> getDatabasePlatform ( ) -> quoteSingleIdentifier ( 'Groups' ) . ' where gID = ?' , [ $ gID ] ) ; if ( $ row ) { $ g = \ Core :: make ( '\Concrete\Core\User\Group\Group' ) ; $ g -> setPropertiesFromArray ( $ row ) ; CacheLocal :: set ( 'group' , $ gID , $ g ) ; return $ g ; } }
Takes the numeric id of a group and returns a group object .
10,144
public static function getByName ( $ gName ) { $ db = Database :: connection ( ) ; $ row = $ db -> fetchAssoc ( 'select * from ' . $ db -> getDatabasePlatform ( ) -> quoteSingleIdentifier ( 'Groups' ) . ' where gName = ?' , [ $ gName ] ) ; if ( $ row ) { $ g = new static ( ) ; $ g -> setPropertiesFromArray ( $ row ) ; return $ g ; } }
Takes the name of a group and returns a group object .
10,145
public static function getByPath ( $ path , $ version = 'RECENT' , TreeInterface $ tree = null ) { $ path = rtrim ( $ path , '/' ) ; $ cache = \ Core :: make ( 'cache/request' ) ; if ( $ tree ) { $ item = $ cache -> getItem ( sprintf ( 'site/page/path/%s/%s' , $ tree -> getSiteTreeID ( ) , trim ( $ path , '/' ) ) ) ; $ cID = $ item -> get ( ) ; if ( $ item -> isMiss ( ) ) { $ db = Database :: connection ( ) ; $ cID = $ db -> fetchColumn ( 'select Pages.cID from PagePaths inner join Pages on Pages.cID = PagePaths.cID where cPath = ? and siteTreeID = ?' , [ $ path , $ tree -> getSiteTreeID ( ) ] ) ; $ cache -> save ( $ item -> set ( $ cID ) ) ; } } else { $ item = $ cache -> getItem ( sprintf ( 'page/path/%s' , trim ( $ path , '/' ) ) ) ; $ cID = $ item -> get ( ) ; if ( $ item -> isMiss ( ) ) { $ db = Database :: connection ( ) ; $ cID = $ db -> fetchColumn ( 'select cID from PagePaths where cPath = ?' , [ $ path ] ) ; $ cache -> save ( $ item -> set ( $ cID ) ) ; } } return self :: getByID ( $ cID , $ version ) ; }
Get a page given its path .
10,146
protected function populatePage ( $ cInfo , $ where , $ cvID ) { $ db = Database :: connection ( ) ; $ q0 = 'select Pages.cID, Pages.pkgID, Pages.siteTreeID, Pages.cPointerID, Pages.cPointerExternalLink, Pages.cIsDraft, Pages.cIsActive, Pages.cIsSystemPage, Pages.cPointerExternalLinkNewWindow, Pages.cFilename, Pages.ptID, Collections.cDateAdded, Pages.cDisplayOrder, Collections.cDateModified, cInheritPermissionsFromCID, cInheritPermissionsFrom, cOverrideTemplatePermissions, cCheckedOutUID, cIsTemplate, uID, cPath, cParentID, cChildren, cCacheFullPageContent, cCacheFullPageContentOverrideLifetime, cCacheFullPageContentLifetimeCustom from Pages inner join Collections on Pages.cID = Collections.cID left join PagePaths on (Pages.cID = PagePaths.cID and PagePaths.ppIsCanonical = 1) ' ; $ row = $ db -> fetchAssoc ( $ q0 . $ where , [ $ cInfo ] ) ; if ( $ row !== false && $ row [ 'cPointerID' ] > 0 ) { $ originalRow = $ row ; $ row = $ db -> fetchAssoc ( $ q0 . 'where Pages.cID = ?' , [ $ row [ 'cPointerID' ] ] ) ; } else { $ originalRow = null ; } if ( $ row !== false ) { foreach ( $ row as $ key => $ value ) { $ this -> { $ key } = $ value ; } if ( $ originalRow !== null ) { $ this -> cPointerID = $ originalRow [ 'cPointerID' ] ; $ this -> cIsActive = $ originalRow [ 'cIsActive' ] ; $ this -> cPointerOriginalID = $ originalRow [ 'cID' ] ; $ this -> cPointerOriginalSiteTreeID = $ originalRow [ 'siteTreeID' ] ; $ this -> cPath = $ originalRow [ 'cPath' ] ; $ this -> cParentID = $ originalRow [ 'cParentID' ] ; $ this -> cDisplayOrder = $ originalRow [ 'cDisplayOrder' ] ; } $ this -> isMasterCollection = $ row [ 'cIsTemplate' ] ; $ this -> loadError ( false ) ; if ( $ cvID != false ) { $ this -> loadVersionObject ( $ cvID ) ; } } else { $ this -> loadError ( COLLECTION_NOT_FOUND ) ; } }
Read the data from the database .
10,147
public function isEditMode ( ) { if ( $ this -> getCollectionPath ( ) == STACKS_LISTING_PAGE_PATH ) { return true ; } if ( $ this -> getPageTypeHandle ( ) == STACKS_PAGE_TYPE ) { return true ; } return $ this -> isCheckedOutByMe ( ) ; }
Is the page in edit mode?
10,148
public function getPackageHandle ( ) { if ( ! isset ( $ this -> pkgHandle ) ) { $ this -> pkgHandle = PackageList :: getHandle ( $ this -> pkgID ) ; } return $ this -> pkgHandle ; }
Get the handle the the package that added this page .
10,149
public function forceCheckIn ( ) { $ db = Database :: connection ( ) ; $ q = 'update Pages set cIsCheckedOut = 0, cCheckedOutUID = null, cCheckedOutDatetime = null, cCheckedOutDatetimeLastEdit = null where cID = ?' ; $ db -> executeQuery ( $ q , [ $ this -> cID ] ) ; }
Forces the page to be checked in if its checked out .
10,150
public static function getFromRequest ( Request $ request ) { $ c = $ request -> getCurrentPage ( ) ; if ( is_object ( $ c ) ) { return $ c ; } if ( $ request -> getPath ( ) != '' ) { $ path = $ request -> getPath ( ) ; $ db = Database :: connection ( ) ; $ cID = false ; $ ppIsCanonical = false ; $ site = \ Core :: make ( 'site' ) -> getSite ( ) ; $ treeIDs = [ 0 ] ; foreach ( $ site -> getLocales ( ) as $ locale ) { $ tree = $ locale -> getSiteTree ( ) ; if ( is_object ( $ tree ) ) { $ treeIDs [ ] = $ tree -> getSiteTreeID ( ) ; } } $ treeIDs = implode ( ',' , $ treeIDs ) ; while ( ( ! $ cID ) && $ path ) { $ row = $ db -> fetchAssoc ( 'select pp.cID, ppIsCanonical from PagePaths pp inner join Pages p on pp.cID = p.cID where cPath = ? and siteTreeID in (' . $ treeIDs . ')' , [ $ path ] ) ; if ( ! empty ( $ row ) ) { $ cID = $ row [ 'cID' ] ; if ( $ cID ) { $ cPath = $ path ; $ ppIsCanonical = ( bool ) $ row [ 'ppIsCanonical' ] ; break ; } } $ path = substr ( $ path , 0 , strrpos ( $ path , '/' ) ) ; } if ( $ cID && $ cPath ) { $ c = self :: getByID ( $ cID , 'ACTIVE' ) ; $ c -> cPathFetchIsCanonical = $ ppIsCanonical ; } else { $ c = new self ( ) ; $ c -> loadError ( COLLECTION_NOT_FOUND ) ; } return $ c ; } else { $ cID = $ request -> query -> get ( 'cID' ) ; if ( ! $ cID ) { $ cID = $ request -> request -> get ( 'cID' ) ; } $ cID = Core :: make ( 'helper/security' ) -> sanitizeInt ( $ cID ) ; if ( $ cID ) { $ c = self :: getByID ( $ cID , 'ACTIVE' ) ; } else { $ site = \ Core :: make ( 'site' ) -> getSite ( ) ; $ c = $ site -> getSiteHomePageObject ( 'ACTIVE' ) ; } $ c -> cPathFetchIsCanonical = true ; } return $ c ; }
Uses a Request object to determine which page to load . Queries by path and then by cID .
10,151
public function processArrangement ( $ area_id , $ moved_block_id , $ block_order ) { $ area_handle = Area :: getAreaHandleFromID ( $ area_id ) ; $ db = Database :: connection ( ) ; $ db -> executeQuery ( 'UPDATE CollectionVersionBlockStyles SET arHandle = ? WHERE cID = ? and cvID = ? and bID = ?' , [ $ area_handle , $ this -> getCollectionID ( ) , $ this -> getVersionID ( ) , $ moved_block_id ] ) ; $ db -> executeQuery ( 'UPDATE CollectionVersionBlocks SET arHandle = ? WHERE cID = ? and cvID = ? and bID = ?' , [ $ area_handle , $ this -> getCollectionID ( ) , $ this -> getVersionID ( ) , $ moved_block_id ] ) ; $ update_query = 'UPDATE CollectionVersionBlocks SET cbDisplayOrder = CASE bID' ; $ when_statements = [ ] ; $ update_values = [ ] ; foreach ( $ block_order as $ key => $ block_id ) { $ when_statements [ ] = 'WHEN ? THEN ?' ; $ update_values [ ] = $ block_id ; $ update_values [ ] = $ key ; } $ update_query .= ' ' . implode ( ' ' , $ when_statements ) . ' END WHERE bID in (' . implode ( ',' , array_pad ( [ ] , count ( $ block_order ) , '?' ) ) . ') AND cID = ? AND cvID = ?' ; $ values = array_merge ( $ update_values , $ block_order ) ; $ values = array_merge ( $ values , [ $ this -> getCollectionID ( ) , $ this -> getVersionID ( ) ] ) ; $ db -> executeQuery ( $ update_query , $ values ) ; }
Persist the data associated to a block when it has been moved around in the page .
10,152
public function isCheckedOut ( ) { $ db = Database :: connection ( ) ; if ( isset ( $ this -> isCheckedOutCache ) ) { return $ this -> isCheckedOutCache ; } $ q = "select cIsCheckedOut, cCheckedOutDatetimeLastEdit from Pages where cID = '{$this->cID}'" ; $ r = $ db -> executeQuery ( $ q ) ; if ( $ r ) { $ row = $ r -> fetchRow ( ) ; if ( ! empty ( $ row [ 'cCheckedOutDatetimeLastEdit' ] ) ) { $ dh = Core :: make ( 'helper/date' ) ; $ timeSinceCheckout = ( $ dh -> getOverridableNow ( true ) - strtotime ( $ row [ 'cCheckedOutDatetimeLastEdit' ] ) ) ; } if ( $ row [ 'cIsCheckedOut' ] == 0 ) { return false ; } else { if ( isset ( $ timeSinceCheckout ) && $ timeSinceCheckout > CHECKOUT_TIMEOUT ) { $ this -> forceCheckIn ( ) ; $ this -> isCheckedOutCache = false ; return false ; } else { $ this -> isCheckedOutCache = true ; return true ; } } } }
Is the page checked out?
10,153
public function getCollectionCheckedOutUserName ( ) { $ db = Database :: connection ( ) ; $ query = 'select cCheckedOutUID from Pages where cID = ?' ; $ vals = [ $ this -> cID ] ; $ checkedOutId = $ db -> fetchColumn ( $ query , $ vals ) ; if ( is_object ( UserInfo :: getByID ( $ checkedOutId ) ) ) { $ ui = UserInfo :: getByID ( $ checkedOutId ) ; $ name = $ ui -> getUserName ( ) ; } else { $ name = t ( 'Unknown User' ) ; } return $ name ; }
Gets the user that is editing the current page .
10,154
public static function getDraftsParentPage ( Site $ site = null ) { $ db = Database :: connection ( ) ; $ site = $ site ? $ site : \ Core :: make ( 'site' ) -> getSite ( ) ; $ cParentID = $ db -> fetchColumn ( 'select p.cID from PagePaths pp inner join Pages p on pp.cID = p.cID inner join SiteLocales sl on p.siteTreeID = sl.siteTreeID where cPath = ? and sl.siteID = ?' , [ Config :: get ( 'concrete.paths.drafts' ) , $ site -> getSiteID ( ) ] ) ; return Page :: getByID ( $ cParentID ) ; }
Get the drafts parent page for a specific site .
10,155
public static function getDrafts ( Site $ site ) { $ db = Database :: connection ( ) ; $ nc = self :: getDraftsParentPage ( $ site ) ; $ r = $ db -> executeQuery ( 'select Pages.cID from Pages inner join Collections c on Pages.cID = c.cID where cParentID = ? order by cDateAdded desc' , [ $ nc -> getCollectionID ( ) ] ) ; $ pages = [ ] ; while ( $ row = $ r -> FetchRow ( ) ) { $ entry = self :: getByID ( $ row [ 'cID' ] ) ; if ( is_object ( $ entry ) ) { $ pages [ ] = $ entry ; } } return $ pages ; }
Get the list of draft pages in a specific site .
10,156
public function populateRecursivePages ( $ pages , $ pageRow , $ cParentID , $ level , $ includeThisPage = true ) { $ db = Database :: connection ( ) ; $ children = $ db -> GetAll ( 'select cID, cDisplayOrder from Pages where cParentID = ? order by cDisplayOrder asc' , [ $ pageRow [ 'cID' ] ] ) ; if ( $ includeThisPage ) { $ pages [ ] = [ 'cID' => $ pageRow [ 'cID' ] , 'cDisplayOrder' => isset ( $ pageRow [ 'cDisplayOrder' ] ) ? $ pageRow [ 'cDisplayOrder' ] : null , 'cParentID' => $ cParentID , 'level' => $ level , 'total' => count ( $ children ) , ] ; } ++ $ level ; $ cParentID = $ pageRow [ 'cID' ] ; if ( count ( $ children ) > 0 ) { foreach ( $ children as $ pageRow ) { $ pages = $ this -> populateRecursivePages ( $ pages , $ pageRow , $ cParentID , $ level ) ; } } return $ pages ; }
Create an array containing data about child pages .
10,157
public function queueForDuplicationSort ( $ a , $ b ) { if ( $ a [ 'level' ] > $ b [ 'level' ] ) { return 1 ; } if ( $ a [ 'level' ] < $ b [ 'level' ] ) { return - 1 ; } if ( $ a [ 'cDisplayOrder' ] > $ b [ 'cDisplayOrder' ] ) { return 1 ; } if ( $ a [ 'cDisplayOrder' ] < $ b [ 'cDisplayOrder' ] ) { return - 1 ; } if ( $ a [ 'cID' ] > $ b [ 'cID' ] ) { return 1 ; } if ( $ a [ 'cID' ] < $ b [ 'cID' ] ) { return - 1 ; } return 0 ; }
Sort a list of pages so that the order is correct for the duplication .
10,158
public function queueForDeletion ( ) { $ pages = [ ] ; $ includeThisPage = true ; if ( $ this -> getCollectionPath ( ) == Config :: get ( 'concrete.paths.trash' ) ) { $ includeThisPage = false ; } $ pages = $ this -> populateRecursivePages ( $ pages , [ 'cID' => $ this -> getCollectionID ( ) ] , $ this -> getCollectionParentID ( ) , 0 , $ includeThisPage ) ; usort ( $ pages , [ 'Page' , 'queueForDeletionSort' ] ) ; $ q = Queue :: get ( 'delete_page' ) ; foreach ( $ pages as $ page ) { $ q -> send ( serialize ( $ page ) ) ; } }
Add this page and its subpages to the Delete Page queue .
10,159
public function addAdditionalPagePath ( $ cPath , $ commit = true ) { $ em = \ ORM :: entityManager ( ) ; $ path = new \ Concrete \ Core \ Entity \ Page \ PagePath ( ) ; $ path -> setPagePath ( '/' . trim ( $ cPath , '/' ) ) ; $ path -> setPageObject ( $ this ) ; $ em -> persist ( $ path ) ; if ( $ commit ) { $ em -> flush ( ) ; } return $ path ; }
Add a non - canonical page path to the current page .
10,160
public function setCanonicalPagePath ( $ cPath , $ isAutoGenerated = false ) { $ em = \ ORM :: entityManager ( ) ; $ path = $ this -> getCollectionPathObject ( ) ; if ( is_object ( $ path ) ) { $ path -> setPagePath ( $ cPath ) ; } else { $ path = new \ Concrete \ Core \ Entity \ Page \ PagePath ( ) ; $ path -> setPagePath ( $ cPath ) ; $ path -> setPageObject ( $ this ) ; } $ path -> setPagePathIsAutoGenerated ( $ isAutoGenerated ) ; $ path -> setPagePathIsCanonical ( true ) ; $ em -> persist ( $ path ) ; $ em -> flush ( ) ; }
Set the canonical page path for a page .
10,161
public function getAdditionalPagePaths ( ) { $ em = \ ORM :: entityManager ( ) ; return $ em -> getRepository ( '\Concrete\Core\Entity\Page\PagePath' ) -> findBy ( [ 'cID' => $ this -> getCollectionID ( ) , 'ppIsCanonical' => false , ] ) ; }
Get all the non - canonical page paths of this page .
10,162
public function isBlockAliasedFromMasterCollection ( $ b ) { if ( ! $ b -> isAlias ( ) ) { return false ; } if ( is_null ( $ this -> blocksAliasedFromMasterCollection ) ) { $ db = Database :: connection ( ) ; $ q = 'SELECT cvb.bID FROM CollectionVersionBlocks AS cvb INNER JOIN CollectionVersionBlocks AS cvb2 ON cvb.bID = cvb2.bID AND cvb2.cID = ? WHERE cvb.cID = ? AND cvb.isOriginal = 0 AND cvb.cvID = ? GROUP BY cvb.bID ;' ; $ v = [ $ this -> getMasterCollectionID ( ) , $ this -> getCollectionID ( ) , $ this -> getVersionObject ( ) -> getVersionID ( ) ] ; $ this -> blocksAliasedFromMasterCollection = $ db -> GetCol ( $ q , $ v ) ; } return in_array ( $ b -> getBlockID ( ) , $ this -> blocksAliasedFromMasterCollection ) ; }
Check if a block is an alias from a page default .
10,163
public function getCollectionThemeObject ( ) { if ( ! isset ( $ this -> themeObject ) ) { $ app = Facade :: getFacadeApplication ( ) ; $ tmpTheme = $ app -> make ( ThemeRouteCollection :: class ) -> getThemeByRoute ( $ this -> getCollectionPath ( ) ) ; if ( isset ( $ tmpTheme [ 0 ] ) ) { switch ( $ tmpTheme [ 0 ] ) { case VIEW_CORE_THEME : $ this -> themeObject = new \ Concrete \ Theme \ Concrete \ PageTheme ( ) ; break ; case 'dashboard' : $ this -> themeObject = new \ Concrete \ Theme \ Dashboard \ PageTheme ( ) ; break ; default : $ this -> themeObject = PageTheme :: getByHandle ( $ tmpTheme [ 0 ] ) ; break ; } } elseif ( $ this -> vObj -> pThemeID < 1 ) { $ this -> themeObject = PageTheme :: getSiteTheme ( ) ; } else { $ this -> themeObject = PageTheme :: getByID ( $ this -> vObj -> pThemeID ) ; } } if ( ! $ this -> themeObject ) { $ this -> themeObject = PageTheme :: getSiteTheme ( ) ; } return $ this -> themeObject ; }
Get the collection s theme object .
10,164
public function getCollectionName ( ) { if ( isset ( $ this -> vObj ) ) { return isset ( $ this -> vObj -> cvName ) ? $ this -> vObj -> cvName : null ; } return isset ( $ this -> cvName ) ? $ this -> cvName : null ; }
Get the page name .
10,165
public static function getCollectionParentIDFromChildID ( $ cID ) { $ db = Database :: connection ( ) ; $ q = 'select cParentID from Pages where cID = ?' ; $ cParentID = $ db -> fetchColumn ( $ q , [ $ cID ] ) ; return $ cParentID ; }
Get the parent cID of a page given its cID .
10,166
public function setTheme ( $ pl ) { $ db = Database :: connection ( ) ; $ db -> executeQuery ( 'update CollectionVersions set pThemeID = ? where cID = ? and cvID = ?' , [ $ pl -> getThemeID ( ) , $ this -> cID , $ this -> vObj -> getVersionID ( ) ] ) ; $ this -> themeObject = $ pl ; }
Set the theme of this page .
10,167
public function setPageType ( \ Concrete \ Core \ Page \ Type \ Type $ type = null ) { $ ptID = 0 ; if ( is_object ( $ type ) ) { $ ptID = $ type -> getPageTypeID ( ) ; } $ db = Database :: connection ( ) ; $ db -> executeQuery ( 'update Pages set ptID = ? where cID = ?' , [ $ ptID , $ this -> cID ] ) ; $ this -> ptID = $ ptID ; }
Set the theme for a page using the page object .
10,168
public function getMasterCollectionID ( ) { $ pt = PageType :: getByID ( $ this -> getPageTypeID ( ) ) ; if ( ! is_object ( $ pt ) ) { return 0 ; } $ template = PageTemplate :: getByID ( $ this -> getPageTemplateID ( ) ) ; if ( ! is_object ( $ template ) ) { return 0 ; } $ c = $ pt -> getPageTypePageTemplateDefaultPageObject ( $ template ) ; return $ c -> getCollectionID ( ) ; }
Get the master page of this page given its page template and page type .
10,169
public function getFirstChild ( $ sortColumn = 'cDisplayOrder asc' ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ now = $ app -> make ( 'date' ) -> getOverridableNow ( ) ; $ cID = $ db -> fetchColumn ( <<<EOTselect Pages.cIDfrom Pages inner join CollectionVersions on Pages.cID = CollectionVersions.cIDwhere cParentID = ? and cvIsApproved = 1 and (cvPublishDate is null or cvPublishDate <= ?) and (cvPublishEndDate is null or cvPublishEndDate >= ?)order by {$sortColumn}EOT , [ $ this -> cID , $ now , $ now ] ) ; if ( $ cID && $ cID != $ this -> getSiteHomePageID ( ) ) { return self :: getByID ( $ cID , 'ACTIVE' ) ; } return false ; }
Get the first child of the current page or null if there is no child .
10,170
public function getCollectionChildrenArray ( $ oneLevelOnly = 0 ) { $ this -> childrenCIDArray = [ ] ; $ this -> _getNumChildren ( $ this -> cID , $ oneLevelOnly ) ; return $ this -> childrenCIDArray ; }
Get the list of child page IDs sorted by their display order .
10,171
public function getCollectionChildren ( ) { $ children = [ ] ; $ db = Database :: connection ( ) ; $ q = 'select cID from Pages where cParentID = ? and cIsTemplate = 0 order by cDisplayOrder asc' ; $ r = $ db -> executeQuery ( $ q , [ $ this -> getCollectionID ( ) ] ) ; if ( $ r ) { while ( $ row = $ r -> fetchRow ( ) ) { if ( $ row [ 'cID' ] > 0 ) { $ c = self :: getByID ( $ row [ 'cID' ] ) ; $ children [ ] = $ c ; } } } return $ children ; }
Get the immediate children of the this page .
10,172
public function getPageRelations ( ) { $ em = \ Database :: connection ( ) -> getEntityManager ( ) ; $ r = $ em -> getRepository ( 'Concrete\Core\Entity\Page\Relation\SiblingRelation' ) ; $ relation = $ r -> findOneBy ( [ 'cID' => $ this -> getCollectionID ( ) ] ) ; $ relations = array ( ) ; if ( is_object ( $ relation ) ) { $ allRelations = $ r -> findBy ( [ 'mpRelationID' => $ relation -> getPageRelationID ( ) ] ) ; foreach ( $ allRelations as $ relation ) { if ( $ relation -> getPageID ( ) != $ this -> getCollectionID ( ) && $ relation -> getPageObject ( ) -> getSiteTreeObject ( ) instanceof SiteTree ) { $ relations [ ] = $ relation ; } } } return $ relations ; }
Get the relations of this page .
10,173
public function duplicateAll ( $ nc = null , $ preserveUserID = false , Site $ site = null ) { $ nc2 = $ this -> duplicate ( $ nc , $ preserveUserID , $ site ) ; self :: _duplicateAll ( $ this , $ nc2 , $ preserveUserID , $ site ) ; return $ nc2 ; }
Duplicate this page and all its child pages and return the new Page created .
10,174
protected function _duplicateAll ( $ cParent , $ cNewParent , $ preserveUserID = false , Site $ site = null ) { $ db = Database :: connection ( ) ; $ cID = $ cParent -> getCollectionID ( ) ; $ q = 'select cID, ptHandle from Pages p left join PageTypes pt on p.ptID = pt.ptID where cParentID = ? order by cDisplayOrder asc' ; $ r = $ db -> executeQuery ( $ q , [ $ cID ] ) ; if ( $ r ) { while ( $ row = $ r -> fetchRow ( ) ) { if ( $ row [ 'ptHandle' ] === STACKS_PAGE_TYPE ) { $ tc = Stack :: getByID ( $ row [ 'cID' ] ) ; } else { $ tc = self :: getByID ( $ row [ 'cID' ] ) ; } $ nc = $ tc -> duplicate ( $ cNewParent , $ preserveUserID , $ site ) ; $ tc -> _duplicateAll ( $ tc , $ nc , $ preserveUserID , $ site ) ; } } }
Duplicate all the child pages of a specific page which has already have been duplicated .
10,175
public function duplicate ( $ nc = null , $ preserveUserID = false , TreeInterface $ site = null ) { $ app = Application :: getFacadeApplication ( ) ; $ cloner = $ app -> make ( Cloner :: class ) ; $ clonerOptions = $ app -> build ( ClonerOptions :: class ) -> setKeepOriginalAuthor ( $ preserveUserID ) ; return $ cloner -> clonePage ( $ this , $ clonerOptions , $ nc ? $ nc : null , $ site ) ; }
Duplicate this page and return the new Page created .
10,176
public function moveToTrash ( ) { $ pe = new Event ( $ this ) ; Events :: dispatch ( 'on_page_move_to_trash' , $ pe ) ; $ trash = self :: getByPath ( Config :: get ( 'concrete.paths.trash' ) ) ; $ app = Facade :: getFacadeApplication ( ) ; $ logger = $ app -> make ( 'log/factory' ) -> createLogger ( Channels :: CHANNEL_SITE_ORGANIZATION ) ; $ logger -> notice ( t ( 'Page "%s" at path "%s" Moved to trash' , $ this -> getCollectionName ( ) , $ this -> getCollectionPath ( ) ) ) ; $ this -> move ( $ trash ) ; $ this -> deactivate ( ) ; $ path = $ this -> getCollectionPathObject ( ) ; if ( ! $ path -> isPagePathAutoGenerated ( ) ) { $ path = $ this -> getAutoGeneratedPagePathObject ( ) ; $ this -> setCanonicalPagePath ( $ path -> getPagePath ( ) , true ) ; $ this -> rescanCollectionPath ( ) ; } $ cID = ( $ this -> getCollectionPointerOriginalID ( ) > 0 ) ? $ this -> getCollectionPointerOriginalID ( ) : $ this -> cID ; $ pages = [ ] ; $ pages = $ this -> populateRecursivePages ( $ pages , [ 'cID' => $ cID ] , $ this -> getCollectionParentID ( ) , 0 , false ) ; $ db = Database :: connection ( ) ; foreach ( $ pages as $ page ) { $ db -> executeQuery ( 'update Pages set cIsActive = 0 where cID = ?' , [ $ page [ 'cID' ] ] ) ; } }
Move this page and all its child pages to the trash .
10,177
public static function getHomePageID ( $ page = null ) { if ( $ page ) { if ( ! $ page instanceof self ) { $ page = self :: getByID ( $ page ) ; } if ( $ page instanceof Page ) { $ siteTree = $ page -> getSiteTreeObject ( ) ; if ( $ siteTree !== null ) { return $ siteTree -> getSiteHomePageID ( ) ; } } } $ locale = Application :: getFacadeApplication ( ) -> make ( LocaleService :: class ) -> getDefaultLocale ( ) ; if ( $ locale !== null ) { $ siteTree = $ locale -> getSiteTreeObject ( ) ; if ( $ siteTree != null ) { return $ siteTree -> getSiteHomePageID ( ) ; } } return null ; }
Get the ID of the home page .
10,178
public function getAutoGeneratedPagePathObject ( ) { $ path = new PagePath ( ) ; $ path -> setPagePathIsAutoGenerated ( true ) ; $ path -> setPagePath ( $ this -> computeCanonicalPagePath ( ) ) ; return $ path ; }
Get a new PagePath object with the computed canonical page path .
10,179
public function getNextSubPageDisplayOrder ( ) { $ db = Database :: connection ( ) ; $ max = $ db -> fetchColumn ( 'select max(cDisplayOrder) from Pages where cParentID = ?' , [ $ this -> getCollectionID ( ) ] ) ; return is_numeric ( $ max ) ? ( $ max + 1 ) : 0 ; }
Get the next available display order of child pages .
10,180
public function rescanCollectionPath ( ) { $ newPath = $ this -> generatePagePath ( ) ; $ pathObject = $ this -> getCollectionPathObject ( ) ; $ ppIsAutoGenerated = true ; if ( is_object ( $ pathObject ) && ! $ pathObject -> isPagePathAutoGenerated ( ) ) { $ ppIsAutoGenerated = false ; } $ this -> setCanonicalPagePath ( $ newPath , $ ppIsAutoGenerated ) ; $ this -> rescanSystemPageStatus ( ) ; $ this -> cPath = $ newPath ; $ this -> refreshCache ( ) ; $ children = $ this -> getCollectionChildren ( ) ; if ( count ( $ children ) > 0 ) { $ myCollectionID = $ this -> getCollectionID ( ) ; foreach ( $ children as $ child ) { if ( $ child -> getCollectionID ( ) !== $ myCollectionID ) { $ child -> rescanCollectionPath ( ) ; } } } }
Recalculate the canonical page path for the current page and its sub - pages based on its current version URL slug etc .
10,181
protected function computeCanonicalPagePath ( ) { $ parent = self :: getByID ( $ this -> cParentID ) ; $ parentPath = $ parent -> getCollectionPathObject ( ) ; $ path = '' ; if ( $ parentPath instanceof PagePath ) { $ path = $ parentPath -> getPagePath ( ) ; } $ path .= '/' ; $ cID = ( $ this -> getCollectionPointerOriginalID ( ) > 0 ) ? $ this -> getCollectionPointerOriginalID ( ) : $ this -> cID ; $ stringValidator = Core :: make ( 'helper/validation/strings' ) ; if ( $ stringValidator -> notempty ( $ this -> getCollectionHandle ( ) ) ) { $ path .= $ this -> getCollectionHandle ( ) ; } else if ( ! $ this -> isHomePage ( ) ) { $ path .= $ cID ; } else { $ path = '' ; } $ event = new PagePathEvent ( $ this ) ; $ event -> setPagePath ( $ path ) ; $ event = Events :: dispatch ( 'on_compute_canonical_page_path' , $ event ) ; return $ event -> getPagePath ( ) ; }
Get the canonical path string of this page . This happens before any uniqueness checks get run .
10,182
public function movePageDisplayOrderToBottom ( ) { $ db = Database :: connection ( ) ; $ mx = $ db -> fetchAssoc ( 'select max(cDisplayOrder) as m from Pages where cParentID = ?' , [ $ this -> getCollectionParentID ( ) ] ) ; $ max = $ mx ? $ mx [ 'm' ] : 0 ; ++ $ max ; $ this -> updateDisplayOrder ( $ max ) ; }
Make this page the first child of its parent .
10,183
public function movePageDisplayOrderToSibling ( Page $ c , $ position = 'before' ) { $ myCID = $ this -> getCollectionPointerOriginalID ( ) ? : $ this -> getCollectionID ( ) ; $ relatedCID = $ c -> getCollectionPointerOriginalID ( ) ? : $ c -> getCollectionID ( ) ; $ pageIDs = [ ] ; $ db = Database :: connection ( ) ; $ r = $ db -> executeQuery ( 'select cID from Pages where cParentID = ? and cID <> ? order by cDisplayOrder asc' , [ $ this -> getCollectionParentID ( ) , $ myCID ] ) ; while ( ( $ cID = $ r -> fetchColumn ( ) ) !== false ) { if ( $ cID == $ relatedCID && $ position == 'before' ) { $ pageIDs [ ] = $ myCID ; } $ pageIDs [ ] = $ cID ; if ( $ cID == $ relatedCID && $ position == 'after' ) { $ pageIDs [ ] = $ myCID ; } } $ displayOrder = 0 ; foreach ( $ pageIDs as $ cID ) { $ co = self :: getByID ( $ cID ) ; $ co -> updateDisplayOrder ( $ displayOrder ) ; ++ $ displayOrder ; } }
Move this page before of after another page .
10,184
public function rescanSystemPageStatus ( ) { $ systemPage = false ; $ db = Database :: connection ( ) ; $ cID = $ this -> getCollectionID ( ) ; if ( ! $ this -> isHomePage ( ) ) { if ( $ this -> getSiteTreeID ( ) == 0 ) { $ systemPage = true ; } else { $ cID = ( $ this -> getCollectionPointerOriginalID ( ) > 0 ) ? $ this -> getCollectionPointerOriginalID ( ) : $ this -> getCollectionID ( ) ; $ db = Database :: connection ( ) ; $ path = $ db -> fetchColumn ( 'select cPath from PagePaths where cID = ? and ppIsCanonical = 1' , array ( $ cID ) ) ; if ( $ path ) { $ fragments = explode ( '/' , $ path ) ; $ topPath = '/' . $ fragments [ 1 ] ; $ c = \ Page :: getByPath ( $ topPath ) ; if ( is_object ( $ c ) && ! $ c -> isError ( ) ) { if ( $ c -> getCollectionParentID ( ) == 0 && ! $ c -> isHomePage ( ) ) { $ systemPage = true ; } } } } } if ( $ systemPage ) { $ db -> executeQuery ( 'update Pages set cIsSystemPage = 1 where cID = ?' , array ( $ cID ) ) ; $ this -> cIsSystemPage = true ; } else { $ db -> executeQuery ( 'update Pages set cIsSystemPage = 0 where cID = ?' , array ( $ cID ) ) ; $ this -> cIsSystemPage = false ; } }
Recalculate the is a system page state . Looks at the current page . If the site tree ID is 0 sets system page to true . If the site tree is not user looks at where the page falls in the hierarchy . If it s inside a page at the top level that has 0 as its parent then it is considered a system page .
10,185
public function isInTrash ( ) { return $ this -> getCollectionPath ( ) != Config :: get ( 'concrete.paths.trash' ) && strpos ( $ this -> getCollectionPath ( ) , Config :: get ( 'concrete.paths.trash' ) ) === 0 ; }
Is this page in the trash?
10,186
public function moveToRoot ( ) { $ db = Database :: connection ( ) ; $ db -> executeQuery ( 'update Pages set cParentID = 0 where cID = ?' , [ $ this -> getCollectionID ( ) ] ) ; $ this -> cParentID = 0 ; $ this -> rescanSystemPageStatus ( ) ; }
Make this page child of nothing thus moving it to the root level .
10,187
public function setPageToDraft ( ) { $ db = Database :: connection ( ) ; $ db -> executeQuery ( 'update Pages set cIsDraft = 1 where cID = ?' , [ $ this -> getCollectionID ( ) ] ) ; $ this -> cIsDraft = true ; }
Mark this page as non draft .
10,188
protected function _associateMasterCollectionAttributes ( $ newCID , $ masterCID ) { $ mc = self :: getByID ( $ masterCID , 'ACTIVE' ) ; $ nc = self :: getByID ( $ newCID , 'RECENT' ) ; $ attributes = CollectionKey :: getAttributeValues ( $ mc ) ; foreach ( $ attributes as $ attribute ) { $ value = $ attribute -> getValueObject ( ) ; if ( $ value ) { $ value = clone $ value ; $ nc -> setAttribute ( $ attribute -> getAttributeKey ( ) , $ value ) ; } } }
Duplicate the master collection attributes to a newly created page .
10,189
public static function addHomePage ( TreeInterface $ siteTree = null ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ cParentID = 0 ; $ uID = HOME_UID ; $ data = [ 'name' => HOME_NAME , 'uID' => $ uID , ] ; $ cobj = parent :: createCollection ( $ data ) ; $ cID = $ cobj -> getCollectionID ( ) ; if ( ! is_object ( $ siteTree ) ) { $ site = \ Core :: make ( 'site' ) -> getSite ( ) ; $ siteTree = $ site -> getSiteTreeObject ( ) ; } $ siteTreeID = $ siteTree -> getSiteTreeID ( ) ; $ v = [ $ cID , $ siteTreeID , $ cParentID , $ uID , 'OVERRIDE' , 1 , ( int ) $ cID , 0 ] ; $ q = 'insert into Pages (cID, siteTreeID, cParentID, uID, cInheritPermissionsFrom, cOverrideTemplatePermissions, cInheritPermissionsFromCID, cDisplayOrder) values (?, ?, ?, ?, ?, ?, ?, ?)' ; $ r = $ db -> prepare ( $ q ) ; $ r -> execute ( $ v ) ; if ( ! $ siteTree -> getSiteHomePageID ( ) ) { $ siteTree -> setSiteHomePageID ( $ cID ) ; $ em = $ app -> make ( EntityManagerInterface :: class ) ; $ em -> flush ( $ siteTree ) ; } $ pc = self :: getByID ( $ cID , 'RECENT' ) ; return $ pc ; }
Add the home page to the system . Typically used only by the installation program .
10,190
protected function acquireAreaStylesFromDefaults ( \ Concrete \ Core \ Entity \ Page \ Template $ template ) { $ pt = $ this -> getPageTypeObject ( ) ; if ( is_object ( $ pt ) ) { $ mc = $ pt -> getPageTypePageTemplateDefaultPageObject ( $ template ) ; $ db = Database :: connection ( ) ; $ db -> delete ( 'CollectionVersionAreaStyles' , [ 'cID' => $ this -> getCollectionID ( ) , 'cvID' => $ this -> getVersionID ( ) ] ) ; $ q = 'select issID, arHandle from CollectionVersionAreaStyles where cID = ?' ; $ r = $ db -> executeQuery ( $ q , [ $ mc -> getCollectionID ( ) ] ) ; while ( $ row = $ r -> FetchRow ( ) ) { $ db -> executeQuery ( 'insert into CollectionVersionAreaStyles (cID, cvID, arHandle, issID) values (?, ?, ?, ?)' , [ $ this -> getCollectionID ( ) , $ this -> getVersionID ( ) , $ row [ 'arHandle' ] , $ row [ 'issID' ] , ] ) ; } } }
Copy the area styles from a page template .
10,191
public function setPageDraftTargetParentPageID ( $ cParentID ) { if ( $ cParentID != $ this -> getPageDraftTargetParentPageID ( ) ) { Section :: unregisterPage ( $ this ) ; } $ db = Database :: connection ( ) ; $ cParentID = intval ( $ cParentID ) ; $ db -> executeQuery ( 'update Pages set cDraftTargetParentPageID = ? where cID = ?' , [ $ cParentID , $ this -> cID ] ) ; $ this -> cDraftTargetParentPageID = $ cParentID ; Section :: registerPage ( $ this ) ; }
Set the ID of the draft parent page ID .
10,192
protected function getSiteNameForLocale ( $ locale ) { static $ names = array ( ) ; if ( ! isset ( $ names [ $ locale ] ) ) { $ prevLocale = \ Localization :: activeLocale ( ) ; if ( $ prevLocale !== $ locale ) { \ Localization :: changeLocale ( $ locale ) ; } $ names [ $ locale ] = tc ( 'SiteName' , $ this -> app -> make ( 'site' ) -> getSite ( ) -> getSiteName ( ) ) ; if ( $ prevLocale !== $ locale ) { \ Localization :: changeLocale ( $ prevLocale ) ; } } return $ names [ $ locale ] ; }
Get the localized site name .
10,193
public function getSiteNameForPage ( \ Concrete \ Core \ Page \ Page $ page ) { static $ multilingual ; static $ defaultLocale ; if ( ! isset ( $ multilingual ) ) { $ multilingual = $ this -> app -> make ( 'multilingual/detector' ) -> isEnabled ( ) ; } if ( $ multilingual ) { if ( ! isset ( $ defaultLocale ) ) { $ defaultLocale = $ this -> app -> make ( 'config' ) -> get ( 'concrete.locale' ) ? : Localization :: BASE_LOCALE ; } $ section = Section :: getBySectionOfSite ( $ page ) ; if ( $ section ) { $ locale = $ section -> getLocale ( ) ; } else { $ locale = $ defaultLocale ; } $ siteName = $ this -> getSiteNameForLocale ( $ locale ) ; } else { $ siteName = $ this -> app -> make ( 'site' ) -> getSite ( ) -> getSiteName ( ) ; } return $ siteName ; }
Get the site name localized for a specific page .
10,194
public function shortenURL ( $ strURL ) { $ file = Loader :: helper ( 'file' ) ; $ url = $ file -> getContents ( "http://tinyurl.com/api-create.php?url=" . $ strURL ) ; return $ url ; }
Shortens a given url with the tiny url api .
10,195
public function create ( ) { $ type = NodeType :: getByHandle ( 'file' ) ; if ( ! is_object ( $ type ) ) { NodeType :: add ( 'file' ) ; } $ type = NodeType :: getByHandle ( 'file_folder' ) ; if ( ! is_object ( $ type ) ) { NodeType :: add ( 'file_folder' ) ; } $ type = NodeType :: getByHandle ( 'search_preset' ) ; if ( ! is_object ( $ type ) ) { NodeType :: add ( 'search_preset' ) ; } $ type = TreeType :: getByHandle ( 'file_manager' ) ; if ( ! is_object ( $ type ) ) { TreeType :: add ( 'file_manager' ) ; } $ manager = FileManager :: get ( ) ; if ( ! is_object ( $ manager ) ) { $ manager = FileManager :: add ( ) ; } return $ manager ; }
Creates everything necessary to store files in folders .
10,196
public function csv_export ( ) { $ search = $ this -> app -> make ( 'Concrete\Controller\Search\Users' ) ; $ result = $ search -> getCurrentSearchObject ( ) ; $ headers = [ 'Content-Type' => 'text/csv' , 'Content-Disposition' => 'attachment; filename=concrete5_users.csv' , ] ; $ app = $ this -> app ; $ config = $ this -> app -> make ( 'config' ) ; $ bom = $ config -> get ( 'concrete.export.csv.include_bom' ) ? $ config -> get ( 'concrete.charset_bom' ) : '' ; return StreamedResponse :: create ( function ( ) use ( $ app , $ result , $ bom ) { $ writer = $ app -> build ( UserExporter :: class , [ 'writer' => $ this -> app -> make ( WriterFactory :: class ) -> createFromPath ( 'php://output' , 'w' ) , ] ) ; echo $ bom ; $ writer -> setUnloadDoctrineEveryTick ( 50 ) ; $ writer -> insertHeaders ( ) ; $ writer -> insertList ( $ result -> getItemListObject ( ) ) ; } , 200 , $ headers ) ; }
Export Users using the current search filters into a CSV .
10,197
public function process ( $ dataRowsToSkip = 0 , $ maxDataRows = null , $ collectData = false ) { $ result = $ this -> app -> make ( ImportResult :: class ) ; if ( $ this -> processHeader ( $ result ) ) { if ( $ this -> dryRun !== false ) { $ this -> entityManager -> getConnection ( ) -> beginTransaction ( ) ; } try { $ this -> processData ( $ result , $ dataRowsToSkip , $ maxDataRows , $ collectData ) ; } finally { if ( $ this -> dryRun !== false ) { try { $ this -> entityManager -> getConnection ( ) -> rollBack ( ) ; } catch ( Exception $ foo ) { } } } } return $ result ; }
Process the CSV data .
10,198
protected function processHeader ( ImportResult $ importResult ) { $ result = false ; $ this -> csvSchema = null ; $ csvSchema = null ; $ this -> reader -> each ( function ( $ headerCells , $ rowIndex ) use ( & $ csvSchema ) { $ csvSchema = new CsvSchema ( $ rowIndex , $ headerCells , $ this -> getStaticHeaders ( ) , $ this -> getAttributesMap ( ) ) ; return false ; } ) ; if ( $ csvSchema === null ) { $ importResult -> getErrors ( ) -> add ( t ( "There's no row in the CSV." ) ) ; } elseif ( ! $ csvSchema -> someHeaderRecognized ( ) ) { $ importResult -> addLineProblem ( true , t ( 'None of the CSV columns have been recognized.' ) , $ csvSchema -> getRowIndex ( ) ) ; } else { $ unrecognizedHeaders = $ csvSchema -> getUnrecognizedHeaders ( ) ; if ( count ( $ unrecognizedHeaders ) > 0 ) { $ importResult -> addLineProblem ( false , t ( 'Unrecognized CSV headers: %s' , Misc :: join ( $ unrecognizedHeaders ) ) , $ csvSchema -> getRowIndex ( ) ) ; } $ missingHeaders = $ csvSchema -> getMissingHeaders ( ) ; if ( count ( $ missingHeaders ) > 0 ) { $ importResult -> addLineProblem ( false , t ( 'Missing CSV headers: %s' , Misc :: join ( $ missingHeaders ) ) , $ csvSchema -> getRowIndex ( ) ) ; } $ this -> csvSchema = $ csvSchema ; $ result = true ; } return $ result ; }
Read the header row and initialize the CSV schema .
10,199
protected function processData ( ImportResult $ importResult , $ dataRowsToSkip , $ maxDataRows , $ collectData = false ) { if ( $ collectData !== false ) { $ dataCollected = [ 'attributeKeys' => [ ] , 'attributeControllers' => [ ] , 'data' => [ ] , ] ; } else { $ dataCollected = null ; } if ( $ this -> csvSchema === null ) { $ importResult -> getErrors ( ) -> add ( t ( 'The CSV schema has not been read.' ) ) ; } else { if ( $ dataCollected !== null ) { $ attributeKeysAndControllers = $ this -> getAttributeKeysAndControllers ( ) ; foreach ( $ attributeKeysAndControllers as $ attributeIndex => list ( $ attributeKey , $ attributeController ) ) { $ dataCollected [ 'attributeKeys' ] [ $ attributeIndex ] = $ attributeKey ; $ dataCollected [ 'attributeControllers' ] [ $ attributeIndex ] = $ attributeController ; } } if ( $ maxDataRows !== null ) { $ maxDataRows = ( int ) $ maxDataRows ; } if ( $ maxDataRows === null || $ maxDataRows > 0 ) { $ dataRowsToSkip = ( int ) $ dataRowsToSkip ; $ this -> reader -> setOffset ( 1 + ( $ dataRowsToSkip > 0 ? $ dataRowsToSkip : 0 ) ) ; $ this -> reader -> each ( function ( $ cells , $ rowIndex ) use ( $ importResult , $ maxDataRows , & $ dataCollected , $ collectData ) { $ importResult -> countRowProcessed ( $ rowIndex ) ; $ staticValues = $ this -> csvSchema -> getStaticValues ( $ cells ) ; try { $ object = $ this -> getObjectWithStaticValues ( $ staticValues ) ; } catch ( UserMessageException $ x ) { $ importResult -> addLineProblem ( true , $ x -> getMessage ( ) ) ; $ object = null ; } if ( $ object !== null ) { $ attributesValues = $ this -> csvSchema -> getAttributesValues ( $ cells ) ; $ attributesValueObjects = $ this -> assignCsvAttributes ( $ object , $ attributesValues , $ importResult ) ; $ importResult -> increaseImportSuccessCount ( ) ; if ( $ dataCollected !== null ) { if ( $ collectData === true || count ( $ dataCollected [ 'data' ] ) < $ collectData ) { $ dataCollected [ 'data' ] [ ] = [ 'object' => $ object , 'attributeValues' => $ attributesValueObjects , ] ; } } } return $ maxDataRows === null || $ importResult -> getTotalDataRowsProcessed ( ) < $ maxDataRows ; } ) ; } } if ( $ dataCollected !== null ) { $ importResult -> setDataCollected ( $ dataCollected ) ; } }
Read the data rows and process them .