idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
8,300
|
protected function getLogger ( ) { if ( $ this -> container -> has ( 'logger' ) ) { $ logger = $ this -> container -> get ( 'logger' ) ; \ assert ( $ logger instanceof LoggerInterface ) ; return $ logger ; } return new NullLogger ( ) ; }
|
Proxy for the logger service of the container . If no such service is found a NullLogger is returned .
|
8,301
|
final protected function redirectToList ( ) { $ parameters = [ ] ; if ( $ filter = $ this -> admin -> getFilterParameters ( ) ) { $ parameters [ 'filter' ] = $ filter ; } return $ this -> redirect ( $ this -> admin -> generateUrl ( 'list' , $ parameters ) ) ; }
|
Redirects the user to the list view .
|
8,302
|
protected function isInPreviewMode ( ) { return $ this -> admin -> supportsPreviewMode ( ) && ( $ this -> isPreviewRequested ( ) || $ this -> isPreviewApproved ( ) || $ this -> isPreviewDeclined ( ) ) ; }
|
Returns true if the request is in the preview workflow .
|
8,303
|
protected function getAclUsers ( ) { $ aclUsers = [ ] ; $ userManagerServiceName = $ this -> container -> getParameter ( 'sonata.admin.security.acl_user_manager' ) ; if ( null !== $ userManagerServiceName && $ this -> has ( $ userManagerServiceName ) ) { $ userManager = $ this -> get ( $ userManagerServiceName ) ; if ( method_exists ( $ userManager , 'findUsers' ) ) { $ aclUsers = $ userManager -> findUsers ( ) ; } } return \ is_array ( $ aclUsers ) ? new \ ArrayIterator ( $ aclUsers ) : $ aclUsers ; }
|
Gets ACL users .
|
8,304
|
protected function getAclRoles ( ) { $ aclRoles = [ ] ; $ roleHierarchy = $ this -> container -> getParameter ( 'security.role_hierarchy.roles' ) ; $ pool = $ this -> container -> get ( 'sonata.admin.pool' ) ; foreach ( $ pool -> getAdminServiceIds ( ) as $ id ) { try { $ admin = $ pool -> getInstance ( $ id ) ; } catch ( \ Exception $ e ) { continue ; } $ baseRole = $ admin -> getSecurityHandler ( ) -> getBaseRole ( $ admin ) ; foreach ( $ admin -> getSecurityInformation ( ) as $ role => $ permissions ) { $ role = sprintf ( $ baseRole , $ role ) ; $ aclRoles [ ] = $ role ; } } foreach ( $ roleHierarchy as $ name => $ roles ) { $ aclRoles [ ] = $ name ; $ aclRoles = array_merge ( $ aclRoles , $ roles ) ; } $ aclRoles = array_unique ( $ aclRoles ) ; return \ is_array ( $ aclRoles ) ? new \ ArrayIterator ( $ aclRoles ) : $ aclRoles ; }
|
Gets ACL roles .
|
8,305
|
protected function validateCsrfToken ( $ intention ) { $ request = $ this -> getRequest ( ) ; $ token = $ request -> request -> get ( '_sonata_csrf_token' , false ) ; if ( $ this -> container -> has ( 'security.csrf.token_manager' ) ) { $ valid = $ this -> container -> get ( 'security.csrf.token_manager' ) -> isTokenValid ( new CsrfToken ( $ intention , $ token ) ) ; } else { return ; } if ( ! $ valid ) { throw new HttpException ( 400 , 'The csrf token is not valid, CSRF attack?' ) ; } }
|
Validate CSRF token for action without form .
|
8,306
|
public function getEntity ( $ key ) { if ( \ count ( $ this -> identifier ) > 1 ) { $ entities = $ this -> getEntities ( ) ; return $ entities [ $ key ] ?? null ; } elseif ( $ this -> entities ) { return isset ( $ this -> entities [ $ key ] ) ? $ this -> entities [ $ key ] : null ; } return $ this -> modelManager -> find ( $ this -> class , $ key ) ; }
|
Returns the entity for the given key .
|
8,307
|
public function getIdentifierValues ( $ entity ) { try { return $ this -> modelManager -> getIdentifierValues ( $ entity ) ; } catch ( \ Exception $ e ) { throw new InvalidArgumentException ( sprintf ( 'Unable to retrieve the identifier values for entity %s' , ClassUtils :: getClass ( $ entity ) ) , 0 , $ e ) ; } }
|
Returns the values of the identifier fields of an entity .
|
8,308
|
protected function load ( $ choices ) { if ( \ is_array ( $ choices ) && \ count ( $ choices ) > 0 ) { $ entities = $ choices ; } elseif ( $ this -> query ) { $ entities = $ this -> modelManager -> executeQuery ( $ this -> query ) ; } else { $ entities = $ this -> modelManager -> findBy ( $ this -> class ) ; } if ( null === $ entities ) { return [ ] ; } $ choices = [ ] ; $ this -> entities = [ ] ; foreach ( $ entities as $ key => $ entity ) { if ( $ this -> propertyPath ) { $ value = $ this -> propertyAccessor -> getValue ( $ entity , $ this -> propertyPath ) ; } else { try { $ value = ( string ) $ entity ; } catch ( \ Exception $ e ) { throw new RuntimeException ( sprintf ( 'Unable to convert the entity "%s" to string, provide ' . '"property" option or implement "__toString()" method in your entity.' , ClassUtils :: getClass ( $ entity ) ) , 0 , $ e ) ; } } if ( \ count ( $ this -> identifier ) > 1 ) { $ choices [ $ key ] = $ value ; $ this -> entities [ $ key ] = $ entity ; } else { $ id = current ( $ this -> getIdentifierValues ( $ entity ) ) ; $ choices [ $ id ] = $ value ; $ this -> entities [ $ id ] = $ entity ; } } return $ choices ; }
|
Initializes the choices and returns them .
|
8,309
|
private function getReflProperty ( string $ property ) : ReflectionProperty { if ( ! isset ( $ this -> reflProperties [ $ property ] ) ) { $ this -> reflProperties [ $ property ] = new \ ReflectionProperty ( $ this -> class , $ property ) ; $ this -> reflProperties [ $ property ] -> setAccessible ( true ) ; } return $ this -> reflProperties [ $ property ] ; }
|
Returns the \ ReflectionProperty instance for a property of the underlying class .
|
8,310
|
public function renderListElement ( Environment $ environment , $ object , FieldDescriptionInterface $ fieldDescription , $ params = [ ] ) { $ template = $ this -> getTemplate ( $ fieldDescription , $ fieldDescription -> getAdmin ( ) -> getTemplate ( 'base_list_field' ) , $ environment ) ; return $ this -> render ( $ fieldDescription , $ template , array_merge ( $ params , [ 'admin' => $ fieldDescription -> getAdmin ( ) , 'object' => $ object , 'value' => $ this -> getValueFromFieldDescription ( $ object , $ fieldDescription ) , 'field_description' => $ fieldDescription , ] ) , $ environment ) ; }
|
render a list element from the FieldDescription .
|
8,311
|
public function renderViewElement ( Environment $ environment , FieldDescriptionInterface $ fieldDescription , $ object ) { $ template = $ this -> getTemplate ( $ fieldDescription , '@SonataAdmin/CRUD/base_show_field.html.twig' , $ environment ) ; try { $ value = $ fieldDescription -> getValue ( $ object ) ; } catch ( NoValueException $ e ) { $ value = null ; } return $ this -> render ( $ fieldDescription , $ template , [ 'field_description' => $ fieldDescription , 'object' => $ object , 'value' => $ value , 'admin' => $ fieldDescription -> getAdmin ( ) , ] , $ environment ) ; }
|
render a view element .
|
8,312
|
public function renderViewElementCompare ( Environment $ environment , FieldDescriptionInterface $ fieldDescription , $ baseObject , $ compareObject ) { $ template = $ this -> getTemplate ( $ fieldDescription , '@SonataAdmin/CRUD/base_show_field.html.twig' , $ environment ) ; try { $ baseValue = $ fieldDescription -> getValue ( $ baseObject ) ; } catch ( NoValueException $ e ) { $ baseValue = null ; } try { $ compareValue = $ fieldDescription -> getValue ( $ compareObject ) ; } catch ( NoValueException $ e ) { $ compareValue = null ; } $ baseValueOutput = $ template -> render ( [ 'admin' => $ fieldDescription -> getAdmin ( ) , 'field_description' => $ fieldDescription , 'value' => $ baseValue , ] ) ; $ compareValueOutput = $ template -> render ( [ 'field_description' => $ fieldDescription , 'admin' => $ fieldDescription -> getAdmin ( ) , 'value' => $ compareValue , ] ) ; $ isDiff = $ baseValueOutput !== $ compareValueOutput ; return $ this -> render ( $ fieldDescription , $ template , [ 'field_description' => $ fieldDescription , 'value' => $ baseValue , 'value_compare' => $ compareValue , 'is_diff' => $ isDiff , 'admin' => $ fieldDescription -> getAdmin ( ) , ] , $ environment ) ; }
|
render a compared view element .
|
8,313
|
public function getUrlsafeIdentifier ( $ model , AdminInterface $ admin = null ) { if ( null === $ admin ) { $ admin = $ this -> pool -> getAdminByClass ( ClassUtils :: getClass ( $ model ) ) ; } return $ admin -> getUrlsafeIdentifier ( $ model ) ; }
|
Get the identifiers as a string that is safe to use in a url .
|
8,314
|
final public function getCanonicalizedLocaleForMoment ( array $ context ) { $ locale = strtolower ( str_replace ( '_' , '-' , $ context [ 'app' ] -> getRequest ( ) -> getLocale ( ) ) ) ; if ( ( 'en' === $ lang = substr ( $ locale , 0 , 2 ) ) && ! \ in_array ( $ locale , [ 'en-au' , 'en-ca' , 'en-gb' , 'en-ie' , 'en-nz' ] , true ) ) { return null ; } foreach ( self :: MOMENT_UNSUPPORTED_LOCALES as $ language => $ locales ) { if ( $ language === $ lang && ! \ in_array ( $ locale , $ locales , true ) ) { $ locale = $ language ; } } return $ locale ; }
|
Returns a canonicalized locale for moment NPM library or null if the locale s language is en which doesn t require localization .
|
8,315
|
final public function getCanonicalizedLocaleForSelect2 ( array $ context ) { $ locale = str_replace ( '_' , '-' , $ context [ 'app' ] -> getRequest ( ) -> getLocale ( ) ) ; if ( 'en' === $ lang = substr ( $ locale , 0 , 2 ) ) { return null ; } switch ( $ locale ) { case 'pt' : $ locale = 'pt-PT' ; break ; case 'ug' : $ locale = 'ug-CN' ; break ; case 'zh' : $ locale = 'zh-CN' ; break ; default : if ( ! \ in_array ( $ locale , [ 'pt-BR' , 'pt-PT' , 'ug-CN' , 'zh-CN' , 'zh-TW' ] , true ) ) { $ locale = $ lang ; } } return $ locale ; }
|
Returns a canonicalized locale for select2 NPM library or null if the locale s language is en which doesn t require localization .
|
8,316
|
public function add ( $ line , $ nlBefore = 0 , $ nlAfter = 0 ) { $ output = str_repeat ( "\n" , $ nlBefore ) . $ line . str_repeat ( "\n" , $ nlAfter ) ; if ( fwrite ( $ this -> file , $ output ) === false ) { die ( "There was an error attempting to write to the report file.\n" . $ this -> fullFilePath . "\n" ) ; } }
|
Add a new line to the report .
|
8,317
|
public function addToSection ( $ section , $ test , $ filePath , $ lineNumber , $ codeLine ) { if ( empty ( $ section ) ) { throw new \ Exception ( __METHOD__ . ": The section can not be empty." ) ; } $ this -> sectionBuffers [ $ section ] [ $ filePath ] [ $ test ] [ ] = [ $ lineNumber , $ codeLine ] ; }
|
Add text to the specified section .
|
8,318
|
public function addSections ( ) { foreach ( $ this -> sectionBuffers as $ section => $ filePaths ) { $ this -> add ( '# ' . $ section , 1 , 1 ) ; foreach ( $ filePaths as $ filePath => $ tests ) { $ this -> add ( '#### ' . $ filePath , 0 , 1 ) ; foreach ( $ tests as $ test => $ lines ) { $ this -> add ( '* ' . $ test , 0 , 1 ) ; foreach ( $ lines as $ line ) { $ this -> add ( " * Line {$line[0]}: `" . str_replace ( '`' , '\`' , $ line [ 1 ] ) . "`" , 0 , 1 ) ; } } $ this -> add ( '' , 1 , 0 ) ; } } }
|
Add sections in the buffer to the output .
|
8,319
|
private function recursiveScan ( $ startFolder ) { if ( is_file ( $ startFolder ) ) { $ this -> files [ ] = $ startFolder ; return ; } $ contents = scandir ( $ startFolder ) ; foreach ( $ contents as $ content ) { if ( strpos ( $ content , '.' ) === 0 ) { continue ; } $ path = $ startFolder . DIRECTORY_SEPARATOR . $ content ; if ( is_dir ( $ path ) ) { $ this -> recursiveScan ( $ path ) ; } else { $ fileExtension = pathinfo ( $ content , PATHINFO_EXTENSION ) ; if ( strlen ( $ fileExtension ) == 0 || ! in_array ( $ fileExtension , $ this -> getFileExtensions ( ) ) ) { continue ; } $ this -> files [ ] = $ path ; } } }
|
Perform a recursive scan of the given path to return files only .
|
8,320
|
public function scanNextFile ( ) { $ _file = each ( $ this -> files ) ; if ( $ _file === false ) { return false ; } $ file = $ _file [ 'value' ] ; $ lines = file ( $ file , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ) ; if ( $ lines === false ) { $ lines = [ ] ; } return $ lines ; }
|
Scan the next file in the array and provide back an array of lines .
|
8,321
|
private function printOptionsAndExit ( ) { echo "Available Options:\n" ; foreach ( $ this -> validShortOptions as $ option => $ info ) { echo "-\033[1m{$option}\033[0m\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n\n" ; } foreach ( $ this -> validLongOptions as $ option => $ info ) { echo "--\033[1m{$option}\033[0m\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n\n" ; } exit ; }
|
Print out available options and exit .
|
8,322
|
private function parseOption ( $ rawOption ) { $ regex = "#^(?P<option>-[a-zA-Z]{1}|--[a-zA-Z-]{2,})(?:=(?P<value>['|\"]?.+?['|\"]?))?$#" ; if ( preg_match ( $ regex , trim ( $ rawOption ) , $ matches ) ) { if ( isset ( $ matches [ 'option' ] ) ) { $ option = ltrim ( $ matches [ 'option' ] , '-' ) ; if ( isset ( $ matches [ 'value' ] ) ) { $ value = $ matches [ 'value' ] ; } if ( strlen ( $ option ) == 1 ) { $ validOptions = $ this -> validShortOptions ; } elseif ( strlen ( $ option ) >= 2 ) { $ validOptions = $ this -> validLongOptions ; } if ( ! isset ( $ validOptions [ $ option ] ) ) { die ( "The option `{$option}` does not exist.\n" ) ; } if ( $ validOptions [ $ option ] [ 'value' ] === self :: VALUE_REQUIRED && ! isset ( $ value ) ) { die ( "The option `{$option}` requires a value, but none was given.\n" ) ; } if ( isset ( $ validOptions [ $ option ] [ 'allowed' ] ) || ( isset ( $ validOptions [ $ option ] [ 'comma_delimited' ] ) && $ validOptions [ $ option ] [ 'comma_delimited' ] == true ) ) { $ value = explode ( ',' , $ value ) ; $ value = array_map ( 'trim' , $ value ) ; } if ( isset ( $ validOptions [ $ option ] [ 'allowed' ] ) ) { foreach ( $ value as $ _value ) { if ( ! in_array ( $ _value , $ validOptions [ $ option ] [ 'allowed' ] ) ) { die ( "The value `{$_value}` for `{$option}` is not valid.\n" ) ; } } } $ this -> options [ $ option ] = ( isset ( $ value ) ? $ value : true ) ; } } }
|
Parse a raw option
|
8,323
|
private function enforceOptions ( ) { foreach ( $ this -> validShortOptions as $ option => $ info ) { if ( $ info [ 'option' ] === self :: OPTION_REQUIRED && ! isset ( $ this -> options [ $ option ] ) ) { die ( "The option `{$option}` is required to be given.\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n" ) ; } } foreach ( $ this -> validLongOptions as $ option => $ info ) { if ( $ info [ 'option' ] === self :: OPTION_REQUIRED && ! isset ( $ this -> options [ $ option ] ) ) { die ( "The option `{$option}` is required to be given.\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n" ) ; } } }
|
Enforce usage of required options .
|
8,324
|
private function run ( ) { $ issues = [ ] ; $ totalFiles = 0 ; $ totalLines = 0 ; $ filePath = $ this -> scanner -> getCurrentFilePath ( ) ; if ( ! $ this -> options -> getOption ( 't' ) || in_array ( 'syntax' , $ this -> options -> getOption ( 't' ) , true ) ) { $ checkSyntax = true ; $ versionGood = $ this -> tests -> getPHPVersion ( ) ; if ( ! $ versionGood ) { $ this -> reporter -> add ( "ERROR! Syntax checking was selected and a PHP binary lower than 7.0.0-dev was specified." , 0 , 1 ) ; } } else { $ checkSyntax = false ; } while ( ( $ lines = $ this -> scanner -> scanNextFile ( ) ) !== false ) { $ totalFiles ++ ; $ grabLineNumber = null ; $ grabLine = null ; if ( $ checkSyntax ) { $ syntax = $ this -> tests -> checkSyntax ( $ filePath ) ; if ( ! isset ( $ syntax [ 'is_valid' ] ) ) { $ grabLineNumber = $ syntax [ 'line' ] ; } } foreach ( $ lines as $ index => $ line ) { $ lineNumber = $ index + 1 ; $ line = trim ( $ line , "\r\n" ) ; if ( $ lineNumber == $ grabLineNumber ) { $ grabLine = $ line ; } $ totalLines ++ ; $ issues = $ this -> tests -> testLine ( $ line ) ; foreach ( $ issues as $ section => $ tests ) { foreach ( $ tests as $ test => $ true ) { $ this -> reporter -> addToSection ( $ section , $ test , $ filePath , $ lineNumber , $ line ) ; } } } if ( $ checkSyntax && $ grabLine !== null ) { $ this -> reporter -> addToSection ( 'syntax' , 'syntax' , $ filePath , $ grabLineNumber , $ grabLine . ' //' . $ syntax [ 'error' ] ) ; } $ filePath = $ this -> scanner -> getCurrentFilePath ( ) ; } $ this -> reporter -> add ( "Processed {$totalLines} lines contained in {$totalFiles} files." , 0 , 1 ) ; }
|
Run tests generator report sections .
|
8,325
|
static public function getRealPath ( $ path ) { if ( strpos ( $ path , '~' ) === 0 ) { $ path = substr_replace ( $ path , $ _SERVER [ 'HOME' ] , 0 , 1 ) ; } $ _path = realpath ( $ path ) ; if ( ! empty ( $ path ) && $ _path !== false ) { return rtrim ( $ _path , DIRECTORY_SEPARATOR ) ; } return false ; }
|
Get a full real path name to a given path .
|
8,326
|
protected function getExtensionEntity ( ) { if ( ! isset ( $ this -> extensionEntity ) ) { $ processId = $ this -> getProcessId ( ) ; $ this -> extensionEntity = $ this -> getEntityManager ( ) -> getEntity ( 'Extension' , $ processId ) ; if ( ! isset ( $ this -> extensionEntity ) ) { throw new Error ( 'Extension Entity not found.' ) ; } } return $ this -> extensionEntity ; }
|
Get entity of this extension
|
8,327
|
public function normalizeOptions ( array $ options ) { $ options [ 'useSsl' ] = ( bool ) ( $ options [ 'useSsl' ] == 'SSL' ) ; $ options [ 'useStartTls' ] = ( bool ) ( $ options [ 'useStartTls' ] == 'TLS' ) ; $ options [ 'accountCanonicalForm' ] = $ this -> accountCanonicalFormMap [ $ options [ 'accountCanonicalForm' ] ] ; return $ options ; }
|
Normalize options to LDAP client format
|
8,328
|
public function getOption ( $ name , $ returns = null ) { if ( ! isset ( $ this -> options ) ) { $ this -> getOptions ( ) ; } if ( isset ( $ this -> options [ $ name ] ) ) { return $ this -> options [ $ name ] ; } return $ returns ; }
|
Get an ldap option
|
8,329
|
public function getLdapClientOptions ( ) { $ options = $ this -> getOptions ( ) ; $ zendOptions = array_diff_key ( $ options , array_flip ( $ this -> permittedEspoOptions ) ) ; return $ zendOptions ; }
|
Get Zend options for using Zend \ Ldap
|
8,330
|
public function jobCheckNewVersion ( $ data ) { $ config = $ this -> getConfig ( ) ; if ( ! $ config -> get ( 'adminNotifications' ) || ! $ config -> get ( 'adminNotificationsNewVersion' ) ) { return true ; } $ latestRelease = $ this -> getLatestRelease ( ) ; if ( empty ( $ latestRelease [ 'version' ] ) ) { $ config -> set ( 'latestVersion' , $ latestRelease [ 'version' ] ) ; $ config -> save ( ) ; return true ; } if ( $ config -> get ( 'latestVersion' ) != $ latestRelease [ 'version' ] ) { $ config -> set ( 'latestVersion' , $ latestRelease [ 'version' ] ) ; if ( ! empty ( $ latestRelease [ 'notes' ] ) ) { } $ config -> save ( ) ; return true ; } if ( ! empty ( $ latestRelease [ 'notes' ] ) ) { } return true ; }
|
Job for checking a new version of EspoCRM
|
8,331
|
public function jobCheckNewExtensionVersion ( $ data ) { $ config = $ this -> getConfig ( ) ; if ( ! $ config -> get ( 'adminNotifications' ) || ! $ config -> get ( 'adminNotificationsNewExtensionVersion' ) ) { return true ; } $ pdo = $ this -> getEntityManager ( ) -> getPDO ( ) ; $ query = " SELECT id, name, version, check_version_url as url FROM extension WHERE deleted = 0 AND is_installed = 1 ORDER BY created_at " ; $ sth = $ pdo -> prepare ( $ query ) ; $ sth -> execute ( ) ; $ rowList = $ sth -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; $ latestReleases = [ ] ; foreach ( $ rowList as $ row ) { $ url = ! empty ( $ row [ 'url' ] ) ? $ row [ 'url' ] : null ; $ extensionName = $ row [ 'name' ] ; $ latestRelease = $ this -> getLatestRelease ( $ url , [ 'name' => $ extensionName , ] ) ; if ( ! empty ( $ latestRelease ) && ! isset ( $ latestRelease [ 'error' ] ) ) { $ latestReleases [ $ extensionName ] = $ latestRelease ; } } $ latestExtensionVersions = $ config -> get ( 'latestExtensionVersions' , [ ] ) ; $ save = false ; foreach ( $ latestReleases as $ extensionName => $ extensionData ) { if ( empty ( $ latestExtensionVersions [ $ extensionName ] ) ) { $ latestExtensionVersions [ $ extensionName ] = $ extensionData [ 'version' ] ; $ save = true ; continue ; } if ( $ latestExtensionVersions [ $ extensionName ] != $ extensionData [ 'version' ] ) { $ latestExtensionVersions [ $ extensionName ] = $ extensionData [ 'version' ] ; if ( ! empty ( $ extensionData [ 'notes' ] ) ) { } $ save = true ; continue ; } if ( ! empty ( $ extensionData [ 'notes' ] ) ) { } } if ( $ save ) { $ config -> set ( 'latestExtensionVersions' , $ latestExtensionVersions ) ; $ config -> save ( ) ; } return true ; }
|
Job for cheking a new version of installed extensions
|
8,332
|
protected function getData ( ) { $ currentLanguage = $ this -> getLanguage ( ) ; if ( ! isset ( $ this -> data [ $ currentLanguage ] ) ) { $ this -> init ( ) ; } return $ this -> data [ $ currentLanguage ] ; }
|
Get data of Unifier language files
|
8,333
|
public function delete ( $ scope , $ category , $ name ) { if ( is_array ( $ name ) ) { foreach ( $ name as $ rowLabel ) { $ this -> delete ( $ scope , $ category , $ rowLabel ) ; } return ; } $ this -> deletedData [ $ scope ] [ $ category ] [ ] = $ name ; $ currentLanguage = $ this -> getLanguage ( ) ; if ( ! isset ( $ this -> data [ $ currentLanguage ] ) ) { $ this -> init ( ) ; } if ( isset ( $ this -> data [ $ currentLanguage ] [ $ scope ] [ $ category ] [ $ name ] ) ) { unset ( $ this -> data [ $ currentLanguage ] [ $ scope ] [ $ category ] [ $ name ] ) ; } if ( isset ( $ this -> changedData [ $ scope ] [ $ category ] [ $ name ] ) ) { unset ( $ this -> changedData [ $ scope ] [ $ category ] [ $ name ] ) ; } }
|
Remove a label
|
8,334
|
private function getForeignLink ( $ parentLinkName , $ parentLinkParams , $ currentEntityDefs ) { if ( isset ( $ parentLinkParams [ 'foreign' ] ) && isset ( $ currentEntityDefs [ 'links' ] [ $ parentLinkParams [ 'foreign' ] ] ) ) { return array ( 'name' => $ parentLinkParams [ 'foreign' ] , 'params' => $ currentEntityDefs [ 'links' ] [ $ parentLinkParams [ 'foreign' ] ] , ) ; } return false ; }
|
Get foreign Link
|
8,335
|
protected function getClassName ( $ name ) { $ name = Util :: normilizeClassName ( $ name ) ; $ data = $ this -> getAll ( ) ; $ name = ucfirst ( $ name ) ; if ( isset ( $ data [ $ name ] ) ) { return $ data [ $ name ] ; } return false ; }
|
Get class name of a job
|
8,336
|
public function isCronConfigured ( ) { $ r1From = new \ DateTime ( '-' . $ this -> checkingCronPeriod ) ; $ r1To = new \ DateTime ( '+' . $ this -> checkingCronPeriod ) ; $ r2From = new \ DateTime ( '- 1 hour' ) ; $ r2To = new \ DateTime ( ) ; $ format = \ Espo \ Core \ Utils \ DateTime :: $ systemDateTimeFormat ; $ selectParams = [ 'select' => [ 'id' ] , 'leftJoins' => [ 'scheduledJob' ] , 'whereClause' => [ 'OR' => [ [ [ 'executedAt>=' => $ r2From -> format ( $ format ) ] , [ 'executedAt<=' => $ r2To -> format ( $ format ) ] , ] , [ [ 'executeTime>=' => $ r1From -> format ( $ format ) ] , [ 'executeTime<=' => $ r1To -> format ( $ format ) ] , 'scheduledJob.job' => 'Dummy' ] ] ] ] ; return ! ! $ this -> getEntityManager ( ) -> getRepository ( 'Job' ) -> findOne ( $ selectParams ) ; }
|
Check if crontab is configured properly
|
8,337
|
protected function loginByToken ( $ username , \ Espo \ Entities \ AuthToken $ authToken = null ) { if ( ! isset ( $ authToken ) ) { return null ; } $ userId = $ authToken -> get ( 'userId' ) ; $ user = $ this -> getEntityManager ( ) -> getEntity ( 'User' , $ userId ) ; $ tokenUsername = $ user -> get ( 'userName' ) ; if ( strtolower ( $ username ) != strtolower ( $ tokenUsername ) ) { $ GLOBALS [ 'log' ] -> alert ( 'Unauthorized access attempt for user [' . $ username . '] from IP [' . $ _SERVER [ 'REMOTE_ADDR' ] . ']' ) ; return null ; } $ user = $ this -> getEntityManager ( ) -> getRepository ( 'User' ) -> findOne ( array ( 'whereClause' => array ( 'userName' => $ username , ) ) ) ; return $ user ; }
|
Login by authorization token
|
8,338
|
protected function adminLogin ( $ username , $ password ) { $ hash = $ this -> getPasswordHash ( ) -> hash ( $ password ) ; $ user = $ this -> getEntityManager ( ) -> getRepository ( 'User' ) -> findOne ( [ 'whereClause' => [ 'userName' => $ username , 'password' => $ hash , 'type' => [ 'admin' , 'super-admin' ] ] ] ) ; return $ user ; }
|
Login user with administrator rights
|
8,339
|
protected function createUser ( array $ userData , $ isPortal = false ) { $ GLOBALS [ 'log' ] -> info ( 'Creating new user ...' ) ; $ data = array ( ) ; $ GLOBALS [ 'log' ] -> debug ( 'LDAP: user data: ' . print_r ( $ userData , true ) ) ; $ ldapFields = $ this -> loadFields ( 'ldap' ) ; foreach ( $ ldapFields as $ espo => $ ldap ) { $ ldap = strtolower ( $ ldap ) ; if ( isset ( $ userData [ $ ldap ] [ 0 ] ) ) { $ GLOBALS [ 'log' ] -> debug ( 'LDAP: Create a user wtih [' . $ espo . '] = [' . $ userData [ $ ldap ] [ 0 ] . '].' ) ; $ data [ $ espo ] = $ userData [ $ ldap ] [ 0 ] ; } } if ( $ isPortal ) { $ userFields = $ this -> loadFields ( 'portalUser' ) ; $ userFields [ 'type' ] = 'portal' ; } else { $ userFields = $ this -> loadFields ( 'user' ) ; } foreach ( $ userFields as $ fieldName => $ fieldValue ) { $ data [ $ fieldName ] = $ fieldValue ; } $ this -> getAuth ( ) -> useNoAuth ( ) ; $ user = $ this -> getEntityManager ( ) -> getEntity ( 'User' ) ; $ user -> set ( $ data ) ; $ this -> getEntityManager ( ) -> saveEntity ( $ user ) ; return $ this -> getEntityManager ( ) -> getEntity ( 'User' , $ user -> id ) ; }
|
Create Espo user with data gets from LDAP server
|
8,340
|
protected function findLdapUserDnByUsername ( $ username ) { $ ldapClient = $ this -> getLdapClient ( ) ; $ options = $ this -> getUtils ( ) -> getOptions ( ) ; $ loginFilterString = '' ; if ( ! empty ( $ options [ 'userLoginFilter' ] ) ) { $ loginFilterString = $ this -> convertToFilterFormat ( $ options [ 'userLoginFilter' ] ) ; } $ searchString = '(&(objectClass=' . $ options [ 'userObjectClass' ] . ')(' . $ options [ 'userNameAttribute' ] . '=' . $ username . ')' . $ loginFilterString . ')' ; $ result = $ ldapClient -> search ( $ searchString , null , LDAP \ Client :: SEARCH_SCOPE_SUB ) ; $ GLOBALS [ 'log' ] -> debug ( 'LDAP: user search string: "' . $ searchString . '"' ) ; foreach ( $ result as $ item ) { return $ item [ "dn" ] ; } }
|
Find LDAP user DN by his username
|
8,341
|
protected function convertToFilterFormat ( $ filter ) { $ filter = trim ( $ filter ) ; if ( substr ( $ filter , 0 , 1 ) != '(' ) { $ filter = '(' . $ filter ; } if ( substr ( $ filter , - 1 ) != ')' ) { $ filter = $ filter . ')' ; } return $ filter ; }
|
Check and convert filter item into LDAP format
|
8,342
|
protected function loadFields ( $ type ) { $ options = $ this -> getUtils ( ) -> getOptions ( ) ; $ typeMap = $ type . 'FieldMap' ; $ fields = array ( ) ; foreach ( $ this -> $ typeMap as $ fieldName => $ fieldValue ) { if ( isset ( $ options [ $ fieldValue ] ) ) { $ fields [ $ fieldName ] = $ options [ $ fieldValue ] ; } } return $ fields ; }
|
Load fields for a user
|
8,343
|
public function unify ( array $ paths , $ isReturnModuleNames = false ) { $ data = $ this -> loadData ( $ paths [ 'corePath' ] ) ; if ( ! empty ( $ paths [ 'modulePath' ] ) ) { $ moduleDir = strstr ( $ paths [ 'modulePath' ] , '{*}' , true ) ; $ moduleList = isset ( $ this -> metadata ) ? $ this -> getMetadata ( ) -> getModuleList ( ) : $ this -> getFileManager ( ) -> getFileList ( $ moduleDir , false , '' , false ) ; foreach ( $ moduleList as $ moduleName ) { $ moduleFilePath = str_replace ( '{*}' , $ moduleName , $ paths [ 'modulePath' ] ) ; if ( $ isReturnModuleNames ) { if ( ! isset ( $ data [ $ moduleName ] ) ) { $ data [ $ moduleName ] = array ( ) ; } $ data [ $ moduleName ] = Util :: merge ( $ data [ $ moduleName ] , $ this -> loadData ( $ moduleFilePath ) ) ; continue ; } $ data = Util :: merge ( $ data , $ this -> loadData ( $ moduleFilePath ) ) ; } } if ( ! empty ( $ paths [ 'customPath' ] ) ) { $ data = Util :: merge ( $ data , $ this -> loadData ( $ paths [ 'customPath' ] ) ) ; } return $ data ; }
|
Unite files content
|
8,344
|
protected function loadData ( $ filePath , $ returns = array ( ) ) { if ( file_exists ( $ filePath ) ) { $ content = $ this -> getFileManager ( ) -> getContents ( $ filePath ) ; $ data = Json :: getArrayData ( $ content ) ; if ( empty ( $ data ) ) { $ GLOBALS [ 'log' ] -> warning ( 'FileUnifier::unify() - Empty file or syntax error - [' . $ filePath . ']' ) ; return $ returns ; } return $ data ; } return $ returns ; }
|
Load data from a file
|
8,345
|
public function addLogRecord ( $ scheduledJobId , $ status , $ runTime = null , $ targetId = null , $ targetType = null ) { if ( ! isset ( $ runTime ) ) { $ runTime = date ( 'Y-m-d H:i:s' ) ; } $ entityManager = $ this -> getEntityManager ( ) ; $ scheduledJob = $ entityManager -> getEntity ( 'ScheduledJob' , $ scheduledJobId ) ; if ( ! $ scheduledJob ) { return ; } $ scheduledJob -> set ( 'lastRun' , $ runTime ) ; $ entityManager -> saveEntity ( $ scheduledJob , [ 'silent' => true ] ) ; $ scheduledJobLog = $ entityManager -> getEntity ( 'ScheduledJobLogRecord' ) ; $ scheduledJobLog -> set ( array ( 'scheduledJobId' => $ scheduledJobId , 'name' => $ scheduledJob -> get ( 'name' ) , 'status' => $ status , 'executionTime' => $ runTime , 'targetId' => $ targetId , 'targetType' => $ targetType ) ) ; $ scheduledJobLogId = $ entityManager -> saveEntity ( $ scheduledJobLog ) ; return $ scheduledJobLogId ; }
|
Add record to ScheduledJobLogRecord about executed job
|
8,346
|
public function getFieldDefsByType ( $ fieldDef ) { if ( is_string ( $ fieldDef ) ) { $ fieldDef = array ( 'type' => $ fieldDef ) ; } if ( isset ( $ fieldDef [ 'type' ] ) ) { return $ this -> getMetadata ( ) -> get ( 'fields.' . $ fieldDef [ 'type' ] ) ; } return null ; }
|
Get field defenition by type in metadata fields key
|
8,347
|
public function getAdditionalFieldList ( $ fieldName , array $ fieldParams , array $ definitionList ) { if ( empty ( $ fieldParams [ 'type' ] ) || empty ( $ definitionList ) ) { return ; } $ fieldType = $ fieldParams [ 'type' ] ; $ fieldDefinition = isset ( $ definitionList [ $ fieldType ] ) ? $ definitionList [ $ fieldType ] : null ; if ( isset ( $ fieldDefinition ) && ! empty ( $ fieldDefinition [ 'fields' ] ) && is_array ( $ fieldDefinition [ 'fields' ] ) ) { $ copiedParams = array_intersect_key ( $ fieldParams , array_flip ( $ this -> copiedDefParams ) ) ; $ additionalFields = array ( ) ; foreach ( $ fieldDefinition [ 'fields' ] as $ subFieldName => $ subFieldParams ) { $ namingType = isset ( $ fieldDefinition [ 'naming' ] ) ? $ fieldDefinition [ 'naming' ] : $ this -> defaultNaming ; $ subFieldNaming = Util :: getNaming ( $ fieldName , $ subFieldName , $ namingType ) ; $ additionalFields [ $ subFieldNaming ] = array_merge ( $ copiedParams , $ subFieldParams ) ; } return $ additionalFields ; } }
|
Get additional field list based on field definition in metadata fields
|
8,348
|
protected function getPhpRequiredList ( $ requiredOnly , array $ additionalData = null ) { $ requiredList = [ 'requiredPhpVersion' , 'requiredPhpLibs' , ] ; if ( ! $ requiredOnly ) { $ requiredList = array_merge ( $ requiredList , [ 'recommendedPhpLibs' , 'recommendedPhpParams' , ] ) ; } return $ this -> getRequiredList ( 'phpRequirements' , $ requiredList , $ additionalData ) ; }
|
Get required php params
|
8,349
|
protected function getDatabaseRequiredList ( $ requiredOnly , array $ additionalData = null ) { $ databaseTypeName = 'Mysql' ; $ databaseHelper = $ this -> getDatabaseHelper ( ) ; $ databaseParams = isset ( $ additionalData [ 'database' ] ) ? $ additionalData [ 'database' ] : null ; $ dbalConnection = $ databaseHelper -> createDbalConnection ( $ databaseParams ) ; if ( $ dbalConnection ) { $ databaseHelper -> setDbalConnection ( $ dbalConnection ) ; $ databaseType = $ databaseHelper -> getDatabaseType ( ) ; $ databaseTypeName = ucfirst ( strtolower ( $ databaseType ) ) ; } $ requiredList = [ 'required' . $ databaseTypeName . 'Version' , ] ; if ( ! $ requiredOnly ) { $ requiredList = array_merge ( $ requiredList , [ 'recommended' . $ databaseTypeName . 'Params' , 'connection' , ] ) ; } return $ this -> getRequiredList ( 'databaseRequirements' , $ requiredList , $ additionalData ) ; }
|
Get required database params
|
8,350
|
protected function checkPhpRequirements ( $ type , $ data , array $ additionalData = null ) { $ list = [ ] ; switch ( $ type ) { case 'requiredPhpVersion' : $ actualVersion = $ this -> getSystemHelper ( ) -> getPhpVersion ( ) ; $ requiredVersion = $ data ; $ acceptable = true ; if ( version_compare ( $ actualVersion , $ requiredVersion ) == - 1 ) { $ acceptable = false ; } $ list [ $ type ] = [ 'type' => 'version' , 'acceptable' => $ acceptable , 'required' => $ requiredVersion , 'actual' => $ actualVersion , ] ; break ; case 'requiredPhpLibs' : case 'recommendedPhpLibs' : foreach ( $ data as $ name ) { $ acceptable = $ this -> getSystemHelper ( ) -> hasPhpLib ( $ name ) ; $ list [ $ name ] = array ( 'type' => 'lib' , 'acceptable' => $ acceptable , 'actual' => $ acceptable ? 'On' : 'Off' , ) ; } break ; case 'recommendedPhpParams' : foreach ( $ data as $ name => $ value ) { $ requiredValue = $ value ; $ actualValue = $ this -> getSystemHelper ( ) -> getPhpParam ( $ name ) ; $ acceptable = ( isset ( $ actualValue ) && Util :: convertToByte ( $ actualValue ) >= Util :: convertToByte ( $ requiredValue ) ) ? true : false ; $ list [ $ name ] = array ( 'type' => 'param' , 'acceptable' => $ acceptable , 'required' => $ requiredValue , 'actual' => $ actualValue , ) ; } break ; } return $ list ; }
|
Check php requirements
|
8,351
|
protected function checkDatabaseRequirements ( $ type , $ data , array $ additionalData = null ) { $ list = [ ] ; $ databaseHelper = $ this -> getDatabaseHelper ( ) ; $ databaseParams = isset ( $ additionalData [ 'database' ] ) ? $ additionalData [ 'database' ] : null ; $ pdo = $ databaseHelper -> createPdoConnection ( $ databaseParams ) ; if ( ! $ pdo ) { $ type = 'connection' ; } switch ( $ type ) { case 'requiredMysqlVersion' : case 'requiredMariadbVersion' : $ actualVersion = $ databaseHelper -> getPdoDatabaseVersion ( $ pdo ) ; $ requiredVersion = $ data ; $ acceptable = true ; if ( version_compare ( $ actualVersion , $ requiredVersion ) == - 1 ) { $ acceptable = false ; } $ list [ $ type ] = [ 'type' => 'version' , 'acceptable' => $ acceptable , 'required' => $ requiredVersion , 'actual' => $ actualVersion , ] ; break ; case 'recommendedMysqlParams' : case 'recommendedMariadbParams' : foreach ( $ data as $ name => $ value ) { $ requiredValue = $ value ; $ actualValue = $ databaseHelper -> getPdoDatabaseParam ( $ name , $ pdo ) ; $ acceptable = false ; switch ( gettype ( $ requiredValue ) ) { case 'integer' : if ( Util :: convertToByte ( $ actualValue ) >= Util :: convertToByte ( $ requiredValue ) ) { $ acceptable = true ; } break ; case 'string' : if ( strtoupper ( $ actualValue ) == strtoupper ( $ requiredValue ) ) { $ acceptable = true ; } break ; } $ list [ $ name ] = array ( 'type' => 'param' , 'acceptable' => $ acceptable , 'required' => $ requiredValue , 'actual' => $ actualValue , ) ; } break ; case 'connection' : if ( ! $ databaseParams ) { $ databaseParams = $ this -> getConfig ( ) -> get ( 'database' ) ; } $ acceptable = true ; if ( ! $ pdo instanceof \ PDO ) { $ acceptable = false ; } $ list [ 'host' ] = [ 'type' => 'connection' , 'acceptable' => $ acceptable , 'actual' => $ databaseParams [ 'host' ] , ] ; $ list [ 'dbname' ] = [ 'type' => 'connection' , 'acceptable' => $ acceptable , 'actual' => $ databaseParams [ 'dbname' ] , ] ; $ list [ 'user' ] = [ 'type' => 'connection' , 'acceptable' => $ acceptable , 'actual' => $ databaseParams [ 'user' ] , ] ; break ; } return $ list ; }
|
Check MySQL requirements
|
8,352
|
public function process ( $ itemName , $ entityName ) { $ inputs = array ( 'itemName' => $ itemName , 'entityName' => $ entityName , ) ; $ this -> setMethods ( $ inputs ) ; $ convertedDefs = $ this -> load ( $ itemName , $ entityName ) ; $ inputs = $ this -> setArrayValue ( null , $ inputs ) ; $ this -> setMethods ( $ inputs ) ; return $ convertedDefs ; }
|
Start process Orm converting for fields
|
8,353
|
protected function backupExistingFiles ( ) { parent :: backupExistingFiles ( ) ; $ backupPath = $ this -> getPath ( 'backupPath' ) ; $ packagePath = $ this -> getPackagePath ( ) ; return $ this -> copy ( array ( $ packagePath , self :: SCRIPTS ) , array ( $ backupPath , self :: SCRIPTS ) , true ) ; }
|
Copy Existing files to backup directory
|
8,354
|
protected function findExtension ( ) { $ manifest = $ this -> getManifest ( ) ; $ this -> extensionEntity = $ this -> getEntityManager ( ) -> getRepository ( 'Extension' ) -> where ( array ( 'name' => $ manifest [ 'name' ] , 'isInstalled' => true , ) ) -> findOne ( ) ; return $ this -> extensionEntity ; }
|
Find Extension entity
|
8,355
|
protected function storeExtension ( ) { $ entityManager = $ this -> getEntityManager ( ) ; $ extensionEntity = $ entityManager -> getEntity ( 'Extension' , $ this -> getProcessId ( ) ) ; if ( ! isset ( $ extensionEntity ) ) { $ extensionEntity = $ entityManager -> getEntity ( 'Extension' ) ; } $ manifest = $ this -> getManifest ( ) ; $ fileList = $ this -> getCopyFileList ( ) ; $ data = array ( 'id' => $ this -> getProcessId ( ) , 'name' => trim ( $ manifest [ 'name' ] ) , 'isInstalled' => true , 'version' => $ manifest [ 'version' ] , 'fileList' => $ fileList , 'description' => $ manifest [ 'description' ] , ) ; if ( ! empty ( $ manifest [ 'checkVersionUrl' ] ) ) { $ data [ 'checkVersionUrl' ] = $ manifest [ 'checkVersionUrl' ] ; } $ extensionEntity -> set ( $ data ) ; return $ entityManager -> saveEntity ( $ extensionEntity ) ; }
|
Create a record of Extension Entity
|
8,356
|
protected function compareVersion ( ) { $ manifest = $ this -> getManifest ( ) ; $ extensionEntity = $ this -> getExtensionEntity ( ) ; if ( isset ( $ extensionEntity ) ) { $ comparedVersion = version_compare ( $ manifest [ 'version' ] , $ extensionEntity -> get ( 'version' ) , '>=' ) ; if ( $ comparedVersion <= 0 ) { $ this -> throwErrorAndRemovePackage ( 'You cannot install an older version of this extension.' ) ; } } }
|
Compare version between installed and a new extensions
|
8,357
|
protected function uninstallExtension ( ) { $ extensionEntity = $ this -> getExtensionEntity ( ) ; $ this -> executeAction ( ExtensionManager :: UNINSTALL , array ( 'id' => $ extensionEntity -> get ( 'id' ) , 'skipSystemRebuild' => true , 'skipAfterScript' => true , ) ) ; }
|
If extension already installed uninstall an old version
|
8,358
|
protected function deleteExtension ( ) { $ extensionEntity = $ this -> getExtensionEntity ( ) ; $ this -> executeAction ( ExtensionManager :: DELETE , array ( 'id' => $ extensionEntity -> get ( 'id' ) ) ) ; }
|
Delete extension package
|
8,359
|
protected function runScript ( $ type ) { $ packagePath = $ this -> getPackagePath ( ) ; $ scriptNames = $ this -> getParams ( 'scriptNames' ) ; $ scriptName = $ scriptNames [ $ type ] ; if ( ! isset ( $ scriptName ) ) { return ; } $ beforeInstallScript = Util :: concatPath ( array ( $ packagePath , self :: SCRIPTS , $ scriptName ) ) . '.php' ; if ( file_exists ( $ beforeInstallScript ) ) { require_once ( $ beforeInstallScript ) ; $ script = new $ scriptName ( ) ; try { $ script -> run ( $ this -> getContainer ( ) , $ this -> scriptParams ) ; } catch ( \ Exception $ e ) { $ this -> throwErrorAndRemovePackage ( $ e -> getMessage ( ) ) ; } } }
|
Run scripts by type
|
8,360
|
protected function getPath ( $ name = 'packagePath' , $ isPackage = false ) { $ postfix = $ isPackage ? $ this -> packagePostfix : '' ; $ processId = $ this -> getProcessId ( ) ; $ path = Util :: concatPath ( $ this -> getParams ( $ name ) , $ processId ) ; return $ path . $ postfix ; }
|
Get package path
|
8,361
|
protected function getDeleteFileList ( ) { if ( ! isset ( $ this -> data [ 'deleteFileList' ] ) ) { $ deleteFileList = array ( ) ; $ deleteList = array_merge ( $ this -> getDeleteList ( 'delete' ) , $ this -> getDeleteList ( 'deleteBeforeCopy' ) , $ this -> getDeleteList ( 'vendor' ) ) ; foreach ( $ deleteList as $ key => $ itemPath ) { if ( is_dir ( $ itemPath ) ) { $ fileList = $ this -> getFileManager ( ) -> getFileList ( $ itemPath , true , '' , true , true ) ; $ fileList = $ this -> concatStringWithArray ( $ itemPath , $ fileList ) ; $ deleteFileList = array_merge ( $ deleteFileList , $ fileList ) ; continue ; } $ deleteFileList [ ] = $ itemPath ; } $ this -> data [ 'deleteFileList' ] = $ deleteFileList ; } return $ this -> data [ 'deleteFileList' ] ; }
|
Get a list of files defined in manifest . json
|
8,362
|
protected function deleteFiles ( $ type = 'delete' , $ withEmptyDirs = false ) { $ deleteList = $ this -> getDeleteList ( $ type ) ; if ( ! empty ( $ deleteList ) ) { return $ this -> getFileManager ( ) -> remove ( $ deleteList , null , $ withEmptyDirs ) ; } return true ; }
|
Delete files defined in a manifest
|
8,363
|
protected function checkManifest ( array $ manifest ) { $ requiredFields = array ( 'name' , 'version' , ) ; foreach ( $ requiredFields as $ fieldName ) { if ( empty ( $ manifest [ $ fieldName ] ) ) { return false ; } } return true ; }
|
Check if the manifest is correct
|
8,364
|
protected function unzipArchive ( $ packagePath = null ) { $ packagePath = isset ( $ packagePath ) ? $ packagePath : $ this -> getPackagePath ( ) ; $ packageArchivePath = $ this -> getPackagePath ( true ) ; if ( ! file_exists ( $ packageArchivePath ) ) { throw new Error ( 'Package Archive doesn\'t exist.' ) ; } $ res = $ this -> getZipUtil ( ) -> unzip ( $ packageArchivePath , $ packagePath ) ; if ( $ res === false ) { throw new Error ( 'Unnable to unzip the file - ' . $ packagePath . '.' ) ; } }
|
Unzip a package archieve
|
8,365
|
protected function deletePackageFiles ( ) { $ packagePath = $ this -> getPackagePath ( ) ; $ res = $ this -> getFileManager ( ) -> removeInDir ( $ packagePath , true ) ; return $ res ; }
|
Delete temporary package files
|
8,366
|
protected function deletePackageArchive ( ) { $ packageArchive = $ this -> getPackagePath ( true ) ; $ res = $ this -> getFileManager ( ) -> removeFile ( $ packageArchive ) ; return $ res ; }
|
Delete temporary package archive
|
8,367
|
protected function executeAction ( $ actionName , $ data ) { $ actionManager = $ this -> getActionManager ( ) ; $ currentAction = $ actionManager -> getAction ( ) ; $ actionManager -> setAction ( $ actionName ) ; $ actionManager -> run ( $ data ) ; $ actionManager -> setAction ( $ currentAction ) ; }
|
Execute an action . For ex . execute uninstall action in install
|
8,368
|
protected function pruneMessage ( array $ record ) { $ message = ( string ) $ record [ 'message' ] ; if ( strlen ( $ message ) > $ this -> maxErrorMessageLength ) { $ record [ 'message' ] = substr ( $ message , 0 , $ this -> maxErrorMessageLength ) . '...' ; $ record [ 'formatted' ] = $ this -> getFormatter ( ) -> format ( $ record ) ; } return ( string ) $ record [ 'formatted' ] ; }
|
Cut the error message depends on maxErrorMessageLength
|
8,369
|
public function hash ( $ password , $ useMd5 = true ) { $ salt = $ this -> getSalt ( ) ; if ( $ useMd5 ) { $ password = md5 ( $ password ) ; } $ hash = crypt ( $ password , $ salt ) ; $ hash = str_replace ( $ salt , '' , $ hash ) ; return $ hash ; }
|
Get hash of a pawword
|
8,370
|
protected function getSalt ( ) { $ salt = $ this -> getConfig ( ) -> get ( 'passwordSalt' ) ; if ( ! isset ( $ salt ) ) { throw new Error ( 'Option "passwordSalt" does not exist in config.php' ) ; } $ salt = $ this -> normalizeSalt ( $ salt ) ; return $ salt ; }
|
Get a salt from config and normalize it
|
8,371
|
public function getLevelCode ( $ levelName ) { $ levelName = strtoupper ( $ levelName ) ; $ levels = $ this -> getLevels ( ) ; if ( isset ( $ levels [ $ levelName ] ) ) { return $ levels [ $ levelName ] ; } return $ levels [ $ this -> defaultLevelName ] ; }
|
Get Level Code
|
8,372
|
protected function mergeWithDefaults ( $ data ) { $ defaultLangFile = 'install/core/i18n/' . $ this -> defaultLanguage . '/install.json' ; $ defaultData = $ this -> getLangData ( $ defaultLangFile ) ; foreach ( $ data as $ categoryName => & $ labels ) { foreach ( $ defaultData [ $ categoryName ] as $ defaultLabelName => $ defaultLabel ) { if ( ! isset ( $ labels [ $ defaultLabelName ] ) ) { $ labels [ $ defaultLabelName ] = $ defaultLabel ; } } } $ data = array_merge ( $ defaultData , $ data ) ; return $ data ; }
|
Merge current language with default one
|
8,373
|
protected function afterRetrieve ( array & $ i18n ) { $ serverType = $ this -> getSystemHelper ( ) -> getServerType ( ) ; $ serverOs = $ this -> getSystemHelper ( ) -> getOs ( ) ; $ rewriteRules = $ this -> getSystemHelper ( ) -> getRewriteRules ( ) ; if ( isset ( $ i18n [ 'options' ] [ 'modRewriteInstruction' ] [ $ serverType ] [ $ serverOs ] ) ) { $ modRewriteInstruction = $ i18n [ 'options' ] [ 'modRewriteInstruction' ] [ $ serverType ] [ $ serverOs ] ; preg_match_all ( '/\{(.*?)\}/' , $ modRewriteInstruction , $ match ) ; if ( isset ( $ match [ 1 ] ) ) { foreach ( $ match [ 1 ] as $ varName ) { if ( isset ( $ rewriteRules [ $ varName ] ) ) { $ modRewriteInstruction = str_replace ( '{' . $ varName . '}' , $ rewriteRules [ $ varName ] , $ modRewriteInstruction ) ; } } } $ i18n [ 'options' ] [ 'modRewriteInstruction' ] [ $ serverType ] [ $ serverOs ] = $ modRewriteInstruction ; } }
|
After retrieve actions
|
8,374
|
protected function exchangeRates ( $ baseCurrency , $ defaultCurrency , array $ currencyRates ) { $ precision = 5 ; $ defaultCurrencyRate = round ( 1 / $ currencyRates [ $ defaultCurrency ] , $ precision ) ; $ exchangedRates = array ( ) ; $ exchangedRates [ $ baseCurrency ] = $ defaultCurrencyRate ; unset ( $ currencyRates [ $ baseCurrency ] , $ currencyRates [ $ defaultCurrency ] ) ; foreach ( $ currencyRates as $ currencyName => $ rate ) { $ exchangedRates [ $ currencyName ] = round ( $ rate * $ defaultCurrencyRate , $ precision ) ; } return $ exchangedRates ; }
|
Calculate exchange rates if defaultCurrency doesn t equals baseCurrency
|
8,375
|
public static function encode ( $ value , $ options = 0 ) { $ json = json_encode ( $ value , $ options ) ; $ error = self :: getLastError ( ) ; if ( $ json === null || ! empty ( $ error ) ) { $ GLOBALS [ 'log' ] -> error ( 'Json::encode():' . $ error . ' - ' . print_r ( $ value , true ) ) ; } return $ json ; }
|
JSON encode a string
|
8,376
|
public static function isJSON ( $ json ) { if ( $ json === '[]' || $ json === '{}' ) { return true ; } else if ( is_array ( $ json ) ) { return false ; } return static :: decode ( $ json ) != null ; }
|
Check if the string is JSON
|
8,377
|
public function getServerType ( ) { $ serverSoft = $ _SERVER [ 'SERVER_SOFTWARE' ] ; preg_match ( '/^(.*?)\//i' , $ serverSoft , $ match ) ; if ( empty ( $ match [ 1 ] ) ) { preg_match ( '/^(.*)\/?/i' , $ serverSoft , $ match ) ; } $ serverName = strtolower ( trim ( $ match [ 1 ] ) ) ; return $ serverName ; }
|
Get web server name
|
8,378
|
protected function sortHooks ( array $ hooks ) { foreach ( $ hooks as $ scopeName => & $ scopeHooks ) { foreach ( $ scopeHooks as $ hookName => & $ hookList ) { usort ( $ hookList , array ( $ this , 'cmpHooks' ) ) ; } } return $ hooks ; }
|
Sort hooks by an order
|
8,379
|
protected function getHookList ( $ scope , $ hookName ) { $ key = $ scope . '_' . $ hookName ; if ( ! isset ( $ this -> hookListHash [ $ key ] ) ) { $ hookList = array ( ) ; if ( isset ( $ this -> data [ 'Common' ] [ $ hookName ] ) ) { $ hookList = $ this -> data [ 'Common' ] [ $ hookName ] ; } if ( isset ( $ this -> data [ $ scope ] [ $ hookName ] ) ) { $ hookList = array_merge ( $ hookList , $ this -> data [ $ scope ] [ $ hookName ] ) ; usort ( $ hookList , array ( $ this , 'cmpHooks' ) ) ; } $ normalizedList = array ( ) ; foreach ( $ hookList as $ hookData ) { $ normalizedList [ ] = $ hookData [ 'className' ] ; } $ this -> hookListHash [ $ key ] = $ normalizedList ; } return $ this -> hookListHash [ $ key ] ; }
|
Get sorted hook list
|
8,380
|
protected function hookExists ( $ className , array $ hookData ) { $ class = preg_replace ( '/^.*\\\(.*)$/' , '$1' , $ className ) ; foreach ( $ hookData as $ hookData ) { if ( preg_match ( '/\\\\' . $ class . '$/' , $ hookData [ 'className' ] ) ) { return true ; } } return false ; }
|
Check if hook exists in the list
|
8,381
|
public function process ( ) { $ entityDefs = $ this -> getEntityDefs ( true ) ; $ ormMetadata = array ( ) ; foreach ( $ entityDefs as $ entityName => $ entityMetadata ) { if ( empty ( $ entityMetadata ) ) { $ GLOBALS [ 'log' ] -> critical ( 'Orm\Converter:process(), Entity:' . $ entityName . ' - metadata cannot be converted into ORM format' ) ; continue ; } $ ormMetadata = Util :: merge ( $ ormMetadata , $ this -> convertEntity ( $ entityName , $ entityMetadata ) ) ; } $ ormMetadata = $ this -> afterProcess ( $ ormMetadata ) ; return $ ormMetadata ; }
|
Orm metadata convertation process
|
8,382
|
protected function convertFields ( $ entityName , & $ entityMetadata ) { $ unmergedFields = array ( 'name' , ) ; $ outputMeta = array ( 'id' => array ( 'type' => Entity :: ID , 'dbType' => 'varchar' ) , 'name' => array ( 'type' => isset ( $ entityMetadata [ 'fields' ] [ 'name' ] [ 'type' ] ) ? $ entityMetadata [ 'fields' ] [ 'name' ] [ 'type' ] : Entity :: VARCHAR , 'notStorable' => true ) , 'deleted' => array ( 'type' => Entity :: BOOL , 'default' => false ) ) ; foreach ( $ entityMetadata [ 'fields' ] as $ fieldName => $ fieldParams ) { if ( empty ( $ fieldParams [ 'type' ] ) ) continue ; $ fieldTypeMetadata = $ this -> getMetadataHelper ( ) -> getFieldDefsByType ( $ fieldParams ) ; $ fieldDefs = $ this -> convertField ( $ entityName , $ fieldName , $ fieldParams , $ fieldTypeMetadata ) ; if ( $ fieldDefs !== false ) { if ( isset ( $ outputMeta [ $ fieldName ] ) && ! in_array ( $ fieldName , $ unmergedFields ) ) { $ outputMeta [ $ fieldName ] = array_merge ( $ outputMeta [ $ fieldName ] , $ fieldDefs ) ; } else { $ outputMeta [ $ fieldName ] = $ fieldDefs ; } } if ( isset ( $ fieldTypeMetadata [ 'linkDefs' ] ) ) { $ linkDefs = $ this -> getMetadataHelper ( ) -> getLinkDefsInFieldMeta ( $ entityName , $ fieldParams , $ fieldTypeMetadata [ 'linkDefs' ] ) ; if ( isset ( $ linkDefs ) ) { if ( ! isset ( $ entityMetadata [ 'links' ] ) ) { $ entityMetadata [ 'links' ] = array ( ) ; } $ entityMetadata [ 'links' ] = Util :: merge ( array ( $ fieldName => $ linkDefs ) , $ entityMetadata [ 'links' ] ) ; } } } return $ outputMeta ; }
|
Metadata conversion from Espo format into Doctrine
|
8,383
|
protected function correctFields ( $ entityName , array $ ormMetadata ) { $ entityDefs = $ this -> getEntityDefs ( ) ; $ entityMetadata = $ ormMetadata [ $ entityName ] ; foreach ( $ entityMetadata [ 'fields' ] as $ fieldName => $ fieldParams ) { if ( empty ( $ fieldParams [ 'type' ] ) ) continue ; $ fieldType = ucfirst ( $ fieldParams [ 'type' ] ) ; $ className = '\Espo\Custom\Core\Utils\Database\Orm\Fields\\' . $ fieldType ; if ( ! class_exists ( $ className ) ) { $ className = '\Espo\Core\Utils\Database\Orm\Fields\\' . $ fieldType ; } if ( class_exists ( $ className ) && method_exists ( $ className , 'load' ) ) { $ helperClass = new $ className ( $ this -> metadata , $ ormMetadata , $ entityDefs ) ; $ fieldResult = $ helperClass -> process ( $ fieldName , $ entityName ) ; if ( isset ( $ fieldResult [ 'unset' ] ) ) { $ ormMetadata = Util :: unsetInArray ( $ ormMetadata , $ fieldResult [ 'unset' ] ) ; unset ( $ fieldResult [ 'unset' ] ) ; } $ ormMetadata = Util :: merge ( $ ormMetadata , $ fieldResult ) ; } $ defaultAttributes = $ this -> metadata -> get ( [ 'entityDefs' , $ entityName , 'fields' , $ fieldName , 'defaultAttributes' ] ) ; if ( $ defaultAttributes && array_key_exists ( $ fieldName , $ defaultAttributes ) ) { $ defaultMetadataPart = array ( $ entityName => array ( 'fields' => array ( $ fieldName => array ( 'default' => $ defaultAttributes [ $ fieldName ] ) ) ) ) ; $ ormMetadata = Util :: merge ( $ ormMetadata , $ defaultMetadataPart ) ; } } $ scopeDefs = $ this -> getMetadata ( ) -> get ( 'scopes.' . $ entityName ) ; if ( isset ( $ scopeDefs [ 'stream' ] ) && $ scopeDefs [ 'stream' ] ) { if ( ! isset ( $ entityMetadata [ 'fields' ] [ 'isFollowed' ] ) ) { $ ormMetadata [ $ entityName ] [ 'fields' ] [ 'isFollowed' ] = array ( 'type' => 'varchar' , 'notStorable' => true , 'notExportable' => true , ) ; $ ormMetadata [ $ entityName ] [ 'fields' ] [ 'followersIds' ] = array ( 'type' => 'jsonArray' , 'notStorable' => true , 'notExportable' => true , ) ; $ ormMetadata [ $ entityName ] [ 'fields' ] [ 'followersNames' ] = array ( 'type' => 'jsonObject' , 'notStorable' => true , 'notExportable' => true , ) ; } } return $ ormMetadata ; }
|
Correct fields defenitions based on \ Espo \ Custom \ Core \ Utils \ Database \ Orm \ Fields
|
8,384
|
public function unify ( $ name , $ paths , $ recursively = false ) { $ content = $ this -> unifySingle ( $ paths [ 'corePath' ] , $ name , $ recursively ) ; if ( ! empty ( $ paths [ 'modulePath' ] ) ) { $ customDir = strstr ( $ paths [ 'modulePath' ] , '{*}' , true ) ; $ moduleList = isset ( $ this -> metadata ) ? $ this -> getMetadata ( ) -> getModuleList ( ) : $ this -> getFileManager ( ) -> getFileList ( $ customDir , false , '' , false ) ; foreach ( $ moduleList as $ moduleName ) { $ curPath = str_replace ( '{*}' , $ moduleName , $ paths [ 'modulePath' ] ) ; if ( $ this -> useObjects ) { $ content = Utils \ DataUtil :: merge ( $ content , $ this -> unifySingle ( $ curPath , $ name , $ recursively , $ moduleName ) ) ; } else { $ content = Utils \ Util :: merge ( $ content , $ this -> unifySingle ( $ curPath , $ name , $ recursively , $ moduleName ) ) ; } } } if ( ! empty ( $ paths [ 'customPath' ] ) ) { if ( $ this -> useObjects ) { $ content = Utils \ DataUtil :: merge ( $ content , $ this -> unifySingle ( $ paths [ 'customPath' ] , $ name , $ recursively ) ) ; } else { $ content = Utils \ Util :: merge ( $ content , $ this -> unifySingle ( $ paths [ 'customPath' ] , $ name , $ recursively ) ) ; } } return $ content ; }
|
Unite file content to the file
|
8,385
|
protected function unifyGetContents ( $ paths , $ defaults ) { $ fileContent = $ this -> getFileManager ( ) -> getContents ( $ paths ) ; if ( $ this -> useObjects ) { $ decoded = Utils \ Json :: decode ( $ fileContent ) ; } else { $ decoded = Utils \ Json :: getArrayData ( $ fileContent , null ) ; } if ( ! isset ( $ decoded ) ) { $ GLOBALS [ 'log' ] -> emergency ( 'Syntax error in ' . Utils \ Util :: concatPath ( $ paths ) ) ; if ( $ this -> useObjects ) { return ( object ) [ ] ; } else { return array ( ) ; } } return $ decoded ; }
|
Helpful method for get content from files for unite Files
|
8,386
|
public function get ( $ name , $ default = null ) { $ keys = explode ( '.' , $ name ) ; $ lastBranch = $ this -> loadConfig ( ) ; foreach ( $ keys as $ keyName ) { if ( isset ( $ lastBranch [ $ keyName ] ) && ( is_array ( $ lastBranch ) || is_object ( $ lastBranch ) ) ) { if ( is_array ( $ lastBranch ) ) { $ lastBranch = $ lastBranch [ $ keyName ] ; } else { $ lastBranch = $ lastBranch -> $ keyName ; } } else { return $ default ; } } return $ lastBranch ; }
|
Get an option from config
|
8,387
|
public function has ( $ name ) { $ keys = explode ( '.' , $ name ) ; $ lastBranch = $ this -> loadConfig ( ) ; foreach ( $ keys as $ keyName ) { if ( isset ( $ lastBranch [ $ keyName ] ) && ( is_array ( $ lastBranch ) || is_object ( $ lastBranch ) ) ) { if ( is_array ( $ lastBranch ) ) { $ lastBranch = $ lastBranch [ $ keyName ] ; } else { $ lastBranch = $ lastBranch -> $ keyName ; } } else { return false ; } } return true ; }
|
Whether parameter is set
|
8,388
|
public function set ( $ name , $ value = null , $ dontMarkDirty = false ) { if ( is_object ( $ name ) ) { $ name = get_object_vars ( $ name ) ; } if ( ! is_array ( $ name ) ) { $ name = array ( $ name => $ value ) ; } foreach ( $ name as $ key => $ value ) { if ( in_array ( $ key , $ this -> associativeArrayAttributeList ) && is_object ( $ value ) ) { $ value = ( array ) $ value ; } $ this -> data [ $ key ] = $ value ; if ( ! $ dontMarkDirty ) { $ this -> changedData [ $ key ] = $ value ; } } }
|
Set an option to the config
|
8,389
|
public function remove ( $ name ) { if ( array_key_exists ( $ name , $ this -> data ) ) { unset ( $ this -> data [ $ name ] ) ; $ this -> removeData [ ] = $ name ; return true ; } return null ; }
|
Remove an option in config
|
8,390
|
public function updateCacheTimestamp ( $ onlyValue = false ) { $ timestamp = [ $ this -> cacheTimestamp => time ( ) ] ; if ( $ onlyValue ) { return $ timestamp ; } return $ this -> set ( $ timestamp ) ; }
|
Update cache timestamp
|
8,391
|
public function run ( $ data ) { $ processId = $ data [ 'id' ] ; $ GLOBALS [ 'log' ] -> debug ( 'Installation process [' . $ processId . ']: start run.' ) ; if ( empty ( $ processId ) ) { throw new Error ( 'Installation package ID was not specified.' ) ; } $ this -> setProcessId ( $ processId ) ; $ this -> initialize ( ) ; $ packagePath = $ this -> getPackagePath ( ) ; if ( ! file_exists ( $ packagePath ) ) { $ this -> unzipArchive ( ) ; $ this -> isAcceptable ( ) ; } $ this -> checkIsWritable ( ) ; $ this -> enableMaintenanceMode ( ) ; $ this -> beforeRunAction ( ) ; $ this -> backupExistingFiles ( ) ; if ( ! $ this -> copyFiles ( 'before' ) ) { $ this -> throwErrorAndRemovePackage ( 'Cannot copy beforeInstall files.' ) ; } if ( ! isset ( $ data [ 'skipBeforeScript' ] ) || ! $ data [ 'skipBeforeScript' ] ) { $ this -> runScript ( 'before' ) ; } $ this -> deleteFiles ( 'deleteBeforeCopy' , true ) ; if ( ! $ this -> copyFiles ( ) ) { $ this -> throwErrorAndRemovePackage ( 'Cannot copy files.' ) ; } $ this -> deleteFiles ( 'delete' , true ) ; $ this -> deleteFiles ( 'vendor' ) ; $ this -> copyFiles ( 'vendor' ) ; $ this -> disableMaintenanceMode ( ) ; if ( ! isset ( $ data [ 'skipSystemRebuild' ] ) || ! $ data [ 'skipSystemRebuild' ] ) { if ( ! $ this -> systemRebuild ( ) ) { $ this -> throwErrorAndRemovePackage ( 'Error occurred while EspoCRM rebuild.' ) ; } } if ( ! $ this -> copyFiles ( 'after' ) ) { $ this -> throwErrorAndRemovePackage ( 'Cannot copy afterInstall files.' ) ; } if ( ! isset ( $ data [ 'skipAfterScript' ] ) || ! $ data [ 'skipAfterScript' ] ) { $ this -> runScript ( 'after' ) ; } $ this -> afterRunAction ( ) ; $ this -> finalize ( ) ; $ this -> deletePackageFiles ( ) ; if ( $ this -> getManifestParam ( 'skipBackup' ) ) { $ this -> getFileManager ( ) -> removeInDir ( [ $ this -> getPath ( 'backupPath' ) , self :: FILES ] ) ; } $ GLOBALS [ 'log' ] -> debug ( 'Installation process [' . $ processId . ']: end run.' ) ; $ this -> clearCache ( ) ; }
|
Main installation process
|
8,392
|
protected function initRebuildActions ( $ currentSchema = null , $ metadataSchema = null ) { $ methods = array ( 'beforeRebuild' , 'afterRebuild' ) ; $ this -> getClassParser ( ) -> setAllowedMethods ( $ methods ) ; $ rebuildActions = $ this -> getClassParser ( ) -> getData ( $ this -> rebuildActionsPath ) ; $ classes = array ( ) ; foreach ( $ rebuildActions as $ actionName => $ actionClass ) { $ rebuildActionClass = new $ actionClass ( $ this -> metadata , $ this -> config , $ this -> entityManager ) ; if ( isset ( $ currentSchema ) ) { $ rebuildActionClass -> setCurrentSchema ( $ currentSchema ) ; } if ( isset ( $ metadataSchema ) ) { $ rebuildActionClass -> setMetadataSchema ( $ metadataSchema ) ; } foreach ( $ methods as $ methodName ) { if ( method_exists ( $ rebuildActionClass , $ methodName ) ) { $ classes [ $ methodName ] [ ] = $ rebuildActionClass ; } } } $ this -> rebuildActionClasses = $ classes ; }
|
Init Rebuild Actions get all classes and create them
|
8,393
|
protected function executeRebuildActions ( $ action = 'beforeRebuild' ) { if ( ! isset ( $ this -> rebuildActionClasses ) ) { $ this -> initRebuildActions ( ) ; } if ( isset ( $ this -> rebuildActionClasses [ $ action ] ) ) { foreach ( $ this -> rebuildActionClasses [ $ action ] as $ rebuildActionClass ) { $ rebuildActionClass -> $ action ( ) ; } } }
|
Execute actions for RebuildAction classes
|
8,394
|
protected function prepareManyMany ( $ entityName , $ relationParams , $ tables ) { $ tableName = Util :: toUnderScore ( $ relationParams [ 'relationName' ] ) ; if ( $ this -> getSchema ( ) -> hasTable ( $ tableName ) ) { $ GLOBALS [ 'log' ] -> debug ( 'DBAL: Table [' . $ tableName . '] exists.' ) ; return $ this -> getSchema ( ) -> getTable ( $ tableName ) ; } $ table = $ this -> getSchema ( ) -> createTable ( $ tableName ) ; $ table -> addColumn ( 'id' , 'int' , $ this -> getDbFieldParams ( array ( 'type' => 'id' , 'len' => $ this -> defaultLength [ 'int' ] , 'autoincrement' => true , ) ) ) ; $ uniqueIndex = array ( ) ; foreach ( $ relationParams [ 'midKeys' ] as $ index => $ midKey ) { $ columnName = Util :: toUnderScore ( $ midKey ) ; $ table -> addColumn ( $ columnName , $ this -> idParams [ 'dbType' ] , $ this -> getDbFieldParams ( array ( 'type' => 'foreignId' , 'len' => $ this -> idParams [ 'len' ] , ) ) ) ; $ table -> addIndex ( array ( $ columnName ) ) ; $ uniqueIndex [ ] = $ columnName ; } if ( ! empty ( $ relationParams [ 'additionalColumns' ] ) ) { foreach ( $ relationParams [ 'additionalColumns' ] as $ fieldName => $ fieldParams ) { if ( ! isset ( $ fieldParams [ 'type' ] ) ) { $ fieldParams = array_merge ( $ fieldParams , array ( 'type' => 'varchar' , 'len' => $ this -> defaultLength [ 'varchar' ] , ) ) ; } $ table -> addColumn ( Util :: toUnderScore ( $ fieldName ) , $ fieldParams [ 'type' ] , $ this -> getDbFieldParams ( $ fieldParams ) ) ; } } if ( ! empty ( $ relationParams [ 'conditions' ] ) ) { foreach ( $ relationParams [ 'conditions' ] as $ fieldName => $ fieldParams ) { $ uniqueIndex [ ] = Util :: toUnderScore ( $ fieldName ) ; } } if ( ! empty ( $ uniqueIndex ) ) { $ table -> addUniqueIndex ( $ uniqueIndex ) ; } $ table -> addColumn ( 'deleted' , 'bool' , $ this -> getDbFieldParams ( array ( 'type' => 'bool' , 'default' => false , ) ) ) ; $ table -> setPrimaryKey ( array ( "id" ) ) ; return $ table ; }
|
Prepare a relation table for the manyMany relation
|
8,395
|
public static function toCamelCase ( $ name , $ symbol = '_' , $ capitaliseFirstChar = false ) { if ( is_array ( $ name ) ) { foreach ( $ name as & $ value ) { $ value = static :: toCamelCase ( $ value , $ symbol , $ capitaliseFirstChar ) ; } return $ name ; } $ name = lcfirst ( $ name ) ; if ( $ capitaliseFirstChar ) { $ name = ucfirst ( $ name ) ; } return preg_replace_callback ( '/' . $ symbol . '([a-zA-Z])/' , 'static::toCamelCaseConversion' , $ name ) ; }
|
Convert name to Camel Case format ex . camel_case to camelCase
|
8,396
|
public static function fromCamelCase ( $ name , $ symbol = '_' ) { if ( is_array ( $ name ) ) { foreach ( $ name as & $ value ) { $ value = static :: fromCamelCase ( $ value , $ symbol ) ; } return $ name ; } $ name [ 0 ] = strtolower ( $ name [ 0 ] ) ; return preg_replace_callback ( '/([A-Z])/' , function ( $ matches ) use ( $ symbol ) { return $ symbol . strtolower ( $ matches [ 1 ] ) ; } , $ name ) ; }
|
Convert name from Camel Case format . ex . camelCase to camel - case
|
8,397
|
public static function unsetInArrayByValue ( $ needle , array $ haystack , $ reIndex = true ) { $ doReindex = false ; foreach ( $ haystack as $ key => $ value ) { if ( is_array ( $ value ) ) { $ haystack [ $ key ] = static :: unsetInArrayByValue ( $ needle , $ value ) ; } else if ( $ needle === $ value ) { unset ( $ haystack [ $ key ] ) ; if ( $ reIndex ) { $ doReindex = true ; } } } if ( $ doReindex ) { $ haystack = array_values ( $ haystack ) ; } return $ haystack ; }
|
Unset a value in array recursively
|
8,398
|
public static function concatPath ( $ folderPath , $ filePath = null ) { if ( is_array ( $ folderPath ) ) { $ fullPath = '' ; foreach ( $ folderPath as $ path ) { $ fullPath = static :: concatPath ( $ fullPath , $ path ) ; } return static :: fixPath ( $ fullPath ) ; } if ( empty ( $ filePath ) ) { return static :: fixPath ( $ folderPath ) ; } if ( empty ( $ folderPath ) ) { return static :: fixPath ( $ filePath ) ; } if ( substr ( $ folderPath , - 1 ) == static :: getSeparator ( ) || substr ( $ folderPath , - 1 ) == '/' ) { return static :: fixPath ( $ folderPath . $ filePath ) ; } return $ folderPath . static :: getSeparator ( ) . $ filePath ; }
|
Get a full path of the file
|
8,399
|
public static function objectToArray ( $ object ) { if ( is_object ( $ object ) ) { $ object = ( array ) $ object ; } return is_array ( $ object ) ? array_map ( "static::objectToArray" , $ object ) : $ object ; }
|
Convert object to array format recursively
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.