idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
39,700
protected function prepareDataProvider ( ) { $ requestParams = Yii :: $ app -> getRequest ( ) -> getBodyParams ( ) ; if ( empty ( $ requestParams ) ) { $ requestParams = Yii :: $ app -> getRequest ( ) -> getQueryParams ( ) ; } $ filter = null ; if ( $ this -> dataFilter !== null ) { $ this -> dataFilter = Yii :: createObject ( $ this -> dataFilter ) ; if ( $ this -> dataFilter -> load ( $ requestParams ) ) { $ filter = $ this -> dataFilter -> build ( ) ; if ( $ filter === false ) { return $ this -> dataFilter ; } } } $ query = call_user_func ( $ this -> prepareActiveDataQuery ) ; if ( ! empty ( $ filter ) ) { $ query -> andWhere ( $ filter ) ; } $ dataProvider = Yii :: createObject ( [ 'class' => ActiveDataProvider :: class , 'query' => $ query , 'pagination' => $ this -> controller -> pagination , 'sort' => [ 'attributes' => $ this -> controller -> generateSortAttributes ( $ this -> controller -> model -> getNgRestConfig ( ) ) , 'params' => $ requestParams , ] , ] ) ; if ( $ this -> isCachable ( ) && $ this -> controller -> cacheDependency ) { Yii :: $ app -> db -> cache ( function ( ) use ( $ dataProvider ) { $ dataProvider -> prepare ( ) ; } , 0 , Yii :: createObject ( $ this -> controller -> cacheDependency ) ) ; } return $ dataProvider ; }
Prepare the data models based on the ngrest find query .
39,701
public function actionIndex ( $ identifier , $ token ) { $ machine = ProxyMachine :: findOne ( [ 'identifier' => $ identifier , 'is_deleted' => false ] ) ; if ( ! $ machine ) { throw new ForbiddenHttpException ( "Unable to acccess the proxy api." ) ; } if ( sha1 ( $ machine -> access_token ) !== $ token ) { throw new ForbiddenHttpException ( "Unable to acccess the proxy api due to invalid token." ) ; } $ rowsPerRequest = $ this -> module -> proxyRowsPerRequest ; $ config = [ 'rowsPerRequest' => $ rowsPerRequest , 'tables' => [ ] , 'storageFilesCount' => StorageFile :: find ( ) -> count ( ) , ] ; foreach ( Yii :: $ app -> db -> schema -> tableNames as $ table ) { if ( in_array ( $ table , $ this -> ignoreTables ) ) { continue ; } $ schema = Yii :: $ app -> db -> getTableSchema ( $ table ) ; $ rows = ( new Query ( ) ) -> from ( $ table ) -> count ( ) ; $ config [ 'tables' ] [ $ table ] = [ 'pks' => $ schema -> primaryKey , 'name' => $ table , 'rows' => $ rows , 'fields' => $ schema -> columnNames , 'offset_total' => ceil ( $ rows / $ rowsPerRequest ) , ] ; } $ buildToken = Yii :: $ app -> security -> generateRandomString ( 16 ) ; $ build = new ProxyBuild ( ) ; $ build -> detachBehavior ( 'LogBehavior' ) ; $ build -> attributes = [ 'machine_id' => $ machine -> id , 'timestamp' => time ( ) , 'build_token' => sha1 ( $ buildToken ) , 'config' => Json :: encode ( $ config ) , 'is_complet' => 0 , 'expiration_time' => time ( ) + $ this -> module -> proxyExpirationTime ] ; if ( $ build -> save ( ) ) { return [ 'providerUrl' => Url :: base ( true ) . '/admin/api-admin-proxy/data-provider' , 'requestCloseUrl' => Url :: base ( true ) . '/admin/api-admin-proxy/close' , 'fileProviderUrl' => Url :: base ( true ) . '/admin/api-admin-proxy/file-provider' , 'imageProviderUrl' => Url :: base ( true ) . '/admin/api-admin-proxy/image-provider' , 'buildToken' => $ buildToken , 'config' => $ config , ] ; } return $ build -> getErrors ( ) ; }
Gathers basic informations about the build .
39,702
private function ensureBuild ( $ machine , $ buildToken ) { $ build = ProxyBuild :: findOne ( [ 'build_token' => $ buildToken , 'is_complet' => 0 ] ) ; if ( ! $ build ) { throw new ForbiddenHttpException ( "Unable to find a ProxyBuild for the provided token." ) ; } if ( time ( ) > $ build -> expiration_time ) { throw new ForbiddenHttpException ( "The expiration time " . date ( "d.m.Y H:i:s" , $ build -> expiration_time ) . " has exceeded." ) ; } if ( $ build -> proxyMachine -> identifier !== $ machine ) { throw new ForbiddenHttpException ( "Invalid machine identifier for current build." ) ; } return $ build ; }
Make sure the machine and token are valid .
39,703
public function actionDataProvider ( $ machine , $ buildToken , $ table , $ offset ) { $ build = $ this -> ensureBuild ( $ machine , $ buildToken ) ; $ config = $ build -> getTableConfig ( $ table ) ; $ offsetNummeric = $ offset * $ build -> rowsPerRequest ; $ query = ( new Query ( ) ) -> select ( $ config [ 'fields' ] ) -> from ( $ config [ 'name' ] ) -> offset ( $ offsetNummeric ) -> limit ( $ build -> rowsPerRequest ) ; if ( ! empty ( $ config [ 'pks' ] ) && is_array ( $ config [ 'pks' ] ) ) { $ orders = [ ] ; foreach ( $ config [ 'pks' ] as $ pk ) { $ orders [ $ pk ] = SORT_ASC ; } $ query -> orderBy ( $ orders ) ; } return $ query -> all ( ) ; }
Return sql table data .
39,704
public function actionFileProvider ( $ machine , $ buildToken , $ fileId ) { $ build = $ this -> ensureBuild ( $ machine , $ buildToken ) ; if ( $ build ) { if ( ! is_numeric ( $ fileId ) ) { throw new ForbiddenHttpException ( "Invalid file id input." ) ; } $ file = Yii :: $ app -> storage -> getFile ( $ fileId ) ; if ( $ file -> fileExists ) { return Yii :: $ app -> response -> sendFile ( $ file -> serverSource , null , [ 'mimeType' => $ file -> mimeType ] ) -> send ( ) ; } throw new NotFoundHttpException ( "The requested file '" . $ file -> serverSource . "' does not exist in the storage folder." ) ; } }
Return file storage data .
39,705
public function actionImageProvider ( $ machine , $ buildToken , $ imageId ) { $ build = $ this -> ensureBuild ( $ machine , $ buildToken ) ; if ( $ build ) { if ( ! is_numeric ( $ imageId ) ) { throw new ForbiddenHttpException ( "Invalid image id input." ) ; } $ image = Yii :: $ app -> storage -> getImage ( $ imageId ) ; if ( $ image -> fileExists ) { return Yii :: $ app -> response -> sendFile ( $ image -> serverSource ) -> send ( ) ; } throw new NotFoundHttpException ( "The requested image '" . $ image -> serverSource . "' does not exist in the storage folder." ) ; } }
Return image storage data .
39,706
public function actionClose ( $ buildToken ) { $ build = ProxyBuild :: findOne ( [ 'build_token' => $ buildToken , 'is_complet' => 0 ] ) ; if ( ! $ build ) { throw new ForbiddenHttpException ( "Unable to find build from token." ) ; } $ build -> updateAttributes ( [ 'is_complet' => 1 ] ) ; }
Close the current build .
39,707
public function generateDownloadAttributes ( ) { $ attributes = [ ] ; foreach ( $ this -> model -> attributes ( ) as $ key ) { $ attributes [ $ key ] = $ this -> model -> getAttributeLabel ( $ key ) . ' (' . $ key . ')' ; } return $ attributes ; }
Generates an array with all attributes an the corresponding label .
39,708
public function isSortable ( array $ item ) { $ config = Config :: createField ( $ item ) ; return $ config -> getSortField ( ) ? true : false ; }
Indicates whether the current plugin config is sortable or not .
39,709
public function getOrderBy ( ) { if ( $ this -> getConfig ( ) -> getDefaultOrderField ( ) === false ) { return false ; } return $ this -> getConfig ( ) -> getDefaultOrderDirection ( ) . $ this -> getConfig ( ) -> getDefaultOrderField ( ) ; }
Returns the current order by state .
39,710
public function getApiEndpoint ( $ append = null ) { if ( $ append ) { $ append = '/' . ltrim ( $ append , '/' ) ; } return 'admin/' . $ this -> getConfig ( ) -> getApiEndpoint ( ) . $ append ; }
Returns the api endpoint but can add appendix .
39,711
protected function can ( $ type ) { if ( ! array_key_exists ( $ type , $ this -> _canTypes ) ) { $ this -> _canTypes [ $ type ] = Yii :: $ app -> auth -> matchApi ( Yii :: $ app -> adminuser -> getId ( ) , $ this -> config -> apiEndpoint , $ type ) ; } return $ this -> _canTypes [ $ type ] ; }
Checks whether a given type can or can not .
39,712
public function getButtons ( ) { if ( $ this -> _buttons ) { return $ this -> _buttons ; } $ buttons = [ ] ; foreach ( $ this -> getConfig ( ) -> getRelations ( ) as $ rel ) { $ api = Yii :: $ app -> adminmenu -> getApiDetail ( $ rel [ 'apiEndpoint' ] ) ; if ( ! $ api ) { throw new InvalidConfigException ( "The configured api relation '{$rel['apiEndpoint']}' does not exists in the menu elements. Maybe you have no permissions to access this API." ) ; } $ label = empty ( $ rel [ 'tabLabelAttribute' ] ) ? "'{$rel['label']}'" : 'item.' . $ rel [ 'tabLabelAttribute' ] ; $ buttons [ ] = [ 'ngClick' => 'addAndswitchToTab(item.' . $ this -> getPrimaryKey ( ) . ', \'' . $ api [ 'route' ] . '\', \'' . $ rel [ 'arrayIndex' ] . '\', ' . $ label . ', \'' . $ rel [ 'modelClass' ] . '\')' , 'icon' => 'chrome_reader_mode' , 'label' => $ rel [ 'label' ] , ] ; } if ( $ this -> can ( Auth :: CAN_UPDATE ) ) { foreach ( $ this -> getActiveWindows ( ) as $ hash => $ config ) { $ buttons [ ] = [ 'ngClick' => 'getActiveWindow(\'' . $ hash . '\', ' . $ this -> getCompositionKeysForButtonActions ( 'item' ) . ')' , 'icon' => isset ( $ config [ 'objectConfig' ] [ 'icon' ] ) ? $ config [ 'objectConfig' ] [ 'icon' ] : $ config [ 'icon' ] , 'label' => isset ( $ config [ 'objectConfig' ] [ 'label' ] ) ? $ config [ 'objectConfig' ] [ 'label' ] : $ config [ 'label' ] , ] ; } foreach ( $ this -> config -> getActiveButtons ( ) as $ btn ) { $ buttons [ ] = [ 'ngClick' => "callActiveButton('{$btn['hash']}', " . $ this -> getCompositionKeysForButtonActions ( 'item' ) . ", \$event)" , 'icon' => $ btn [ 'icon' ] , 'label' => $ btn [ 'label' ] , ] ; } } if ( $ this -> config -> isDeletable ( ) && $ this -> can ( Auth :: CAN_DELETE ) ) { $ buttons [ ] = [ 'ngClick' => 'deleteItem(' . $ this -> getCompositionKeysForButtonActions ( 'item' ) . ')' , 'icon' => 'delete' , 'label' => '' , ] ; } if ( count ( $ this -> getFields ( 'update' ) ) > 0 && $ this -> can ( Auth :: CAN_UPDATE ) ) { $ buttons [ ] = [ 'ngClick' => 'toggleUpdate(' . $ this -> getCompositionKeysForButtonActions ( 'item' ) . ')' , 'icon' => 'mode_edit' , 'label' => '' , ] ; } $ this -> _buttons = $ buttons ; return $ buttons ; }
collection all the buttons in the crud list .
39,713
public function apiQueryString ( $ type ) { $ query = [ 'ngrestCallType' => $ type ] ; $ fields = [ ] ; foreach ( $ this -> model -> primaryKey ( ) as $ n ) { $ fields [ ] = $ n ; } if ( count ( $ this -> getFields ( $ type ) ) > 0 ) { foreach ( $ this -> getFields ( $ type ) as $ field ) { $ fields [ ] = $ field ; } } if ( count ( $ this -> config -> getPointerExtraFields ( $ type ) ) > 0 ) { $ query [ 'expand' ] = implode ( ',' , $ this -> config -> getPointerExtraFields ( $ type ) ) ; } array_unique ( $ fields ) ; $ query [ 'fields' ] = implode ( "," , $ fields ) ; if ( Yii :: $ app -> request -> get ( 'pool' ) ) { $ query [ 'pool' ] = Yii :: $ app -> request -> get ( 'pool' ) ; } return http_build_query ( $ query , '' , '&' ) ; }
Generate the api query string for a certain context type
39,714
public function getFields ( $ type ) { if ( ! array_key_exists ( $ type , $ this -> _fields ) ) { $ fields = [ ] ; if ( $ this -> config -> hasPointer ( $ type ) ) { foreach ( $ this -> config -> getPointer ( $ type ) as $ item ) { $ fields [ ] = $ item [ 'name' ] ; } } $ this -> _fields [ $ type ] = $ fields ; } return $ this -> _fields [ $ type ] ; }
Short hand method to get all fields for a certain type context
39,715
public function generatePluginHtml ( array $ element , $ configContext ) { if ( $ element [ 'i18n' ] && $ configContext !== self :: TYPE_LIST ) { return $ this -> view -> render ( '_crudform_i18n_pluginhtml' , [ 'element' => $ element , 'configContext' => $ configContext , 'languages' => Lang :: getQuery ( ) , 'helpButtonHtml' => $ this -> createFieldHelpButton ( $ element , $ configContext ) , ] ) ; } $ ngModel = $ this -> ngModelString ( $ configContext , $ element [ 'name' ] ) ; return $ this -> createFieldHelpButton ( $ element , $ configContext ) . $ this -> renderElementPlugins ( $ configContext , $ element [ 'type' ] , Inflector :: slug ( $ ngModel ) , $ element [ 'name' ] , $ ngModel , $ element [ 'alias' ] , false ) ; }
Generate the HTML code for the plugin element based on the current context .
39,716
public function renderElementPlugins ( $ configContext , $ typeConfig , $ uniqueId , $ attribute , $ ngRestModel , $ label , $ elmni18n ) { $ args = $ typeConfig [ 'args' ] ; $ args [ 'renderContext' ] = $ this ; $ obj = NgRest :: createPluginObject ( $ typeConfig [ 'class' ] , $ attribute , $ label , $ elmni18n , $ args ) ; $ method = 'render' . ucfirst ( $ configContext ) ; $ html = $ obj -> $ method ( $ uniqueId , $ ngRestModel ) ; $ content = is_array ( $ html ) ? implode ( " " , $ html ) : $ html ; if ( $ configContext !== self :: TYPE_LIST ) { $ isRequired = $ this -> getModel ( ) -> isAttributeRequired ( $ attribute ) ; if ( $ isRequired ) { $ content = '<span class="bold-form-label">' . $ content . '</span>' ; } } return $ content ; }
Render the input element
39,717
public function i18nNgModelString ( $ configContext , $ attribute , $ lang ) { $ context = $ configContext == self :: TYPE_LIST ? "item." : "data.{$configContext}." ; return $ context . $ attribute . '[\'' . $ lang . '\']' ; }
Generate the ngrest model for an i18n field
39,718
private function evalGroupFields ( $ pointerElements ) { if ( ! $ pointerElements ) { return [ ] ; } $ names = [ ] ; foreach ( $ pointerElements as $ elmn ) { $ names [ $ elmn [ 'name' ] ] = $ elmn [ 'name' ] ; } foreach ( $ this -> getConfig ( ) -> getAttributeGroups ( ) as $ group ) { foreach ( $ group [ 0 ] as $ item ) { if ( in_array ( $ item , $ names ) ) { unset ( $ names [ $ item ] ) ; } } } $ groups [ ] = [ $ names , '__default' , 'collapsed' => true , 'is_default' => true ] ; return array_merge ( $ groups , $ this -> getConfig ( ) -> getAttributeGroups ( ) ) ; }
Generate an array for every group withing the given pointer elemenets .
39,719
public function actionFixTableNames ( ) { $ batch = TagRelation :: find ( ) -> batch ( ) ; $ i = 0 ; $ fixed = 0 ; $ errors = 0 ; foreach ( $ batch as $ rows ) { foreach ( $ rows as $ relation ) { $ i ++ ; $ tableName = TaggableTrait :: cleanBaseTableName ( $ relation -> table_name ) ; if ( $ relation -> table_name !== $ tableName ) { $ relation -> table_name = $ tableName ; if ( $ relation -> save ( ) ) { $ fixed ++ ; } else { $ errors ++ ; } } unset ( $ tableName , $ relation ) ; } } return $ this -> outputSuccess ( "{$i} items checked and {$fixed} items fixed with {$errors} errors." ) ; }
Handle wrong declared table names and try to cleanup not existing relations .
39,720
public function actionCleanup ( ) { $ tagIds = Tag :: find ( ) -> select ( [ 'id' ] ) -> column ( ) ; $ batch = TagRelation :: find ( ) -> batch ( ) ; $ i = 0 ; $ delete = 0 ; foreach ( $ batch as $ rows ) { foreach ( $ rows as $ relation ) { $ i ++ ; if ( ! in_array ( $ relation -> tag_id , $ tagIds ) ) { $ relation -> delete ( ) ; $ delete ++ ; continue ; } $ prefixedTableName = '{{%' . $ relation -> table_name . '}}' ; $ pk = $ this -> tableSchema ( $ prefixedTableName ) -> primaryKey ; $ query = ( new Query ( ) ) -> from ( $ prefixedTableName ) -> where ( [ current ( $ pk ) => $ relation -> pk_id ] ) -> exists ( ) ; if ( ! $ query ) { $ relation -> delete ( ) ; $ delete ++ ; } unset ( $ relation , $ prefixedTableName , $ pk , $ query ) ; } } return $ this -> outputSuccess ( "{$i} items checked and {$delete} items deleted." ) ; }
Handle not existing relations tags which does not exists or relation entries which does not exists in the table .
39,721
public function getJsTranslations ( ) { $ translations = [ ] ; foreach ( $ this -> _jsTranslations as $ module => $ data ) { foreach ( $ data as $ key ) { $ translations [ $ key ] = Yii :: t ( $ module , $ key , [ ] , Yii :: $ app -> language ) ; } } return $ translations ; }
Getter method for the js translations array .
39,722
public function getMenu ( ) { return ( new AdminMenuBuilder ( $ this ) ) -> nodeRoute ( 'menu_node_filemanager' , 'cloud_upload' , 'admin/storage/index' ) -> node ( 'menu_node_system' , 'settings_applications' ) -> group ( 'menu_group_access' ) -> itemApi ( 'menu_access_item_user' , 'admin/user/index' , 'person' , 'api-admin-user' ) -> itemApi ( 'menu_access_item_apiuser' , 'admin/api-user/index' , 'device_hub' , 'api-admin-apiuser' ) -> itemApi ( 'menu_access_item_group' , 'admin/group/index' , 'group' , 'api-admin-group' ) -> group ( 'menu_group_system' ) -> itemApi ( 'menu_system_item_config' , 'admin/config/index' , 'storage' , 'api-admin-config' ) -> itemApi ( 'menu_system_item_language' , 'admin/lang/index' , 'language' , 'api-admin-lang' ) -> itemApi ( 'menu_system_item_tags' , 'admin/tag/index' , 'view_list' , 'api-admin-tag' ) -> itemApi ( 'menu_system_logger' , 'admin/logger/index' , 'notifications' , 'api-admin-logger' ) -> itemApi ( 'Queue' , 'admin/queue-log/index' , 'schedule' , 'api-admin-queuelog' ) -> group ( 'menu_group_images' ) -> itemApi ( 'menu_images_item_effects' , 'admin/effect/index' , 'blur_circular' , 'api-admin-effect' ) -> itemApi ( 'menu_images_item_filters' , 'admin/filter/index' , 'adjust' , 'api-admin-filter' ) -> group ( 'menu_group_contentproxy' ) -> itemApi ( 'menu_group_contentproxy_machines' , 'admin/proxy-machine/index' , 'devices' , 'api-admin-proxymachine' ) -> itemApi ( 'menu_group_contentproxy_builds' , 'admin/proxy-build/index' , 'import_export' , 'api-admin-proxybuild' ) ; }
Get the admin module interface menu .
39,723
public static function t ( $ message , array $ params = [ ] , $ language = null ) { return parent :: baseT ( 'admin' , $ message , $ params , $ language ) ; }
Admin Module translation helper .
39,724
public function actionSession ( ) { $ user = Yii :: $ app -> adminuser -> identity ; $ session = [ 'packages' => [ ] , 'user' => $ user -> toArray ( [ 'title' , 'firstname' , 'lastname' , 'email' , 'id' , 'email_verification_token_timestamp' ] ) , 'activities' => [ 'open_email_validation' => $ this -> hasOpenEmailValidation ( $ user ) ] , 'settings' => Yii :: $ app -> adminuser -> identity -> setting -> getArray ( [ User :: USER_SETTING_ISDEVELOPER , User :: USER_SETTING_UILANGUAGE , User :: USER_SETTING_NEWUSEREMAIL ] , [ User :: USER_SETTING_UILANGUAGE => $ this -> module -> interfaceLanguage , ] ) , ] ; if ( $ session [ 'settings' ] [ User :: USER_SETTING_ISDEVELOPER ] ) { $ session [ 'packages' ] = Yii :: $ app -> getPackageInstaller ( ) -> getConfigs ( ) ; } return $ session ; }
Dump the current data from your user session .
39,725
private function hasOpenEmailValidation ( User $ user ) { $ ts = $ user -> email_verification_token_timestamp ; if ( ! empty ( $ ts ) && ( time ( ) - $ this -> module -> emailVerificationTokenExpirationTime ) <= $ ts ) { return true ; } return false ; }
Ensure whether the current user has an active email verification token or not .
39,726
public function actionChangePassword ( ) { $ model = new UserChangePassword ( ) ; $ model -> setUser ( Yii :: $ app -> adminuser -> identity ) ; $ model -> attributes = Yii :: $ app -> request -> bodyParams ; if ( $ this -> module -> strongPasswordPolicy ) { $ model -> validators -> append ( StrengthValidator :: createValidator ( StrengthValidator :: class , $ model , [ 'newpass' ] ) ) ; } if ( $ model -> validate ( ) ) { $ model -> checkAndStore ( ) ; } return $ model ; }
Action to change the password for the given User .
39,727
public function actionChangeEmail ( ) { $ token = Yii :: $ app -> request -> getBodyParam ( 'token' ) ; $ user = Yii :: $ app -> adminuser -> identity ; if ( ! empty ( $ token ) && sha1 ( $ token ) == $ user -> email_verification_token && $ this -> hasOpenEmailValidation ( $ user ) ) { $ newEmail = $ user -> setting -> get ( User :: USER_SETTING_NEWUSEREMAIL ) ; $ user -> email = $ newEmail ; if ( $ user -> update ( true , [ 'email' ] ) ) { $ user -> resetEmailVerification ( ) ; $ newEmail = $ user -> setting -> remove ( User :: USER_SETTING_NEWUSEREMAIL ) ; return [ 'success' => true ] ; } else { return $ this -> sendModelError ( $ user ) ; } } return $ this -> sendArrayError ( [ 'email' => Module :: t ( 'account_changeemail_wrongtokenorempty' ) ] ) ; }
Action to change the email based on token input .
39,728
public function actionSessionUpdate ( ) { $ identity = Yii :: $ app -> adminuser -> identity ; $ user = clone Yii :: $ app -> adminuser -> identity ; $ user -> attributes = Yii :: $ app -> request -> bodyParams ; $ verify = [ 'title' , 'firstname' , 'lastname' , 'id' ] ; if ( $ user -> validate ( [ 'email' ] ) && $ user -> email !== $ identity -> email && $ this -> module -> emailVerification ) { $ token = $ user -> getAndStoreEmailVerificationToken ( ) ; $ mail = Yii :: $ app -> mail -> compose ( Module :: t ( 'account_changeemail_subject' ) , Module :: t ( 'account_changeemail_body' , [ 'url' => Url :: base ( true ) , 'token' => $ token ] ) ) -> address ( $ identity -> email , $ identity -> firstname . ' ' . $ identity -> lastname ) -> send ( ) ; if ( $ mail ) { $ identity -> setting -> set ( User :: USER_SETTING_NEWUSEREMAIL , $ user -> email ) ; } else { $ user -> addError ( 'email' , Module :: t ( 'account_changeemail_tokensenterror' , [ 'email' => $ identity -> email ] ) ) ; $ identity -> resetEmailVerification ( ) ; } } if ( ! $ this -> module -> emailVerification ) { $ verify [ ] = 'email' ; } if ( ! $ user -> hasErrors ( ) && $ user -> update ( true , $ verify ) !== false ) { return $ user ; } return $ this -> sendModelError ( $ user ) ; }
Update data for the current session user .
39,729
public function actionChangeSettings ( ) { $ params = Yii :: $ app -> request -> bodyParams ; foreach ( $ params as $ param => $ value ) { Yii :: $ app -> adminuser -> identity -> setting -> set ( $ param , $ value ) ; } return true ; }
Change user settings .
39,730
public function actionCleanup ( ) { $ fileList = StorageImporter :: getOrphanedFileList ( ) ; if ( $ fileList === false ) { return $ this -> outputError ( "Could not find the storage folder to clean up." ) ; } if ( count ( $ fileList ) > 0 ) { foreach ( $ fileList as $ fileName ) { $ this -> output ( $ fileName ) ; } $ this -> outputInfo ( count ( $ fileList ) . " files to remove." ) ; } if ( count ( $ fileList ) !== 0 ) { $ success = true ; if ( $ this -> confirm ( "Do you want to delete " . count ( $ fileList ) . " files which are not referenced in the database any more? (can not be undon, maybe create a backup first!)" ) ) { foreach ( $ fileList as $ file ) { if ( is_file ( $ file ) && @ unlink ( $ file ) ) { $ this -> outputSuccess ( $ file . " successful deleted." ) ; } elseif ( is_file ( $ file ) ) { $ this -> outputError ( $ file . " could not be deleted!" ) ; $ success = false ; } else { $ this -> outputError ( $ file . " could not be found!" ) ; $ success = false ; } } } if ( $ success ) { return $ this -> outputSuccess ( count ( $ fileList ) . " files successful deleted." ) ; } return $ this -> outputError ( "Cleanup could not be completed. Please look into error above." ) ; } return $ this -> outputSuccess ( "No orphaned files found." ) ; }
Delete orphaned files but requires user confirmation to ensure delete process .
39,731
public function actionProcessThumbnails ( ) { $ response = Yii :: $ app -> storage -> processThumbnails ( ) ; if ( $ response ) { return $ this -> outputSuccess ( 'Successful generated storage thumbnails.' ) ; } return $ this -> outputError ( 'Error while creating the storage thumbnails.' ) ; }
Create all thumbnails for filemanager preview . Otherwhise they are created on request load .
39,732
public function actionCleanupImageTable ( ) { $ rows = Yii :: $ app -> db -> createCommand ( 'SELECT file_id, filter_id, COUNT(*) as count FROM {{%admin_storage_image}} GROUP BY file_id, filter_id HAVING COUNT(*) > 1' ) -> queryAll ( ) ; if ( empty ( $ rows ) ) { return $ this -> outputInfo ( "no dublications has been detected." ) ; } $ this -> outputInfo ( "dublicated image files detected:" ) ; foreach ( $ rows as $ row ) { $ this -> output ( "> file {$row['file_id']} with filter {$row['filter_id']} found {$row['count']} duplicates." ) ; } if ( $ this -> confirm ( "Do you want to delte the duplicated files in the image storage table?" ) ) { foreach ( $ rows as $ key => $ row ) { $ keep = Yii :: $ app -> db -> createCommand ( 'SELECT id FROM {{%admin_storage_image}} WHERE file_id=:fileId AND filter_id=:filterId ORDER BY id LIMIT 1' , [ ':fileId' => $ row [ 'file_id' ] , ':filterId' => $ row [ 'filter_id' ] , ] ) -> queryOne ( ) ; if ( ! $ keep ) { $ this -> outputError ( 'Unable to find the first row for this delete request. Skip this one' ) ; continue ; } $ remove = Yii :: $ app -> db -> createCommand ( ) -> delete ( '{{%admin_storage_image}}' , 'file_id=:fileId AND filter_id=:filterId AND id!=:id' , [ ':fileId' => $ row [ 'file_id' ] , ':filterId' => $ row [ 'filter_id' ] , ':id' => $ keep [ 'id' ] , ] ) -> execute ( ) ; if ( $ remove ) { $ this -> outputSuccess ( "< Remove {$row['count']} duplications for file {$row['file_id']} with filter {$row['filter_id']}." ) ; } } } return $ this -> outputSuccess ( "all duplications has been removed." ) ; }
See image duplications exists of filter and file id combination and remove them execept of the first created .
39,733
public function checkRouteAccess ( $ route ) { UserOnline :: refreshUser ( $ this -> userAuthClass ( ) -> identity , $ route ) ; if ( ! Yii :: $ app -> auth -> matchRoute ( $ this -> userAuthClass ( ) -> identity -> id , $ route ) ) { throw new ForbiddenHttpException ( 'Unable to access this action due to insufficient permissions.' ) ; } }
Shorthand method to check whether the current use exists for the given route otherwise throw forbidden http exception .
39,734
public function actionIndex ( ) { $ tags = [ ] ; foreach ( TagParser :: getInstantiatedTagObjects ( ) as $ name => $ object ) { $ tags [ ] = [ 'name' => $ name , 'example' => $ object -> example ( ) , 'readme' => Markdown :: process ( $ object -> readme ( ) ) , ] ; } $ this -> view -> registerJs ( 'var i18n=' . Json :: encode ( $ this -> module -> jsTranslations ) , View :: POS_HEAD ) ; $ authToken = UserLogin :: find ( ) -> select ( [ 'auth_token' ] ) -> where ( [ 'user_id' => Yii :: $ app -> adminuser -> id , 'ip' => Yii :: $ app -> request -> userIP , 'is_destroyed' => false ] ) -> scalar ( ) ; $ this -> view -> registerJs ( 'zaa.run([\'$rootScope\', function($rootScope) { $rootScope.luyacfg = ' . Json :: encode ( [ 'authToken' => $ authToken , 'homeUrl' => Url :: home ( true ) , 'i18n' => $ this -> module -> jsTranslations , 'helptags' => $ tags , ] ) . '; }]);' , View :: POS_END ) ; return $ this -> render ( 'index' ) ; }
Render the admin index page .
39,735
public function actionLogout ( ) { if ( ! Yii :: $ app -> adminuser -> logout ( false ) ) { Yii :: $ app -> session -> destroy ( ) ; } return $ this -> redirect ( [ '/admin/login/index' , 'logout' => true ] ) ; }
Trigger user logout .
39,736
public function colorizeValue ( $ value , $ displayValue = false ) { $ text = ( $ displayValue ) ? $ value : Module :: t ( 'debug_state_on' ) ; if ( $ value ) { return '<span style="color:green;">' . $ text . '</span>' ; } return '<span style="color:red;">' . Module :: t ( 'debug_state_off' ) . '</span>' ; }
Context helper for layout main . php in order to colorize debug informations .
39,737
public static function getUploadErrorMessages ( ) { return [ UPLOAD_ERR_OK => Module :: t ( 'upload_err_message_0' ) , UPLOAD_ERR_INI_SIZE => Module :: t ( 'upload_err_message_1' ) , UPLOAD_ERR_FORM_SIZE => Module :: t ( 'upload_err_message_2' ) , UPLOAD_ERR_PARTIAL => Module :: t ( 'upload_err_message_3' ) , UPLOAD_ERR_NO_FILE => Module :: t ( 'upload_err_message_4' ) , UPLOAD_ERR_NO_TMP_DIR => Module :: t ( 'upload_err_message_6' ) , UPLOAD_ERR_CANT_WRITE => Module :: t ( 'upload_err_message_7' ) , UPLOAD_ERR_EXTENSION => Module :: t ( 'upload_err_message_8' ) , ] ; }
Get the file upload error messages .
39,738
public static function removeFile ( $ fileId , $ cleanup = false ) { $ model = StorageFile :: find ( ) -> where ( [ 'id' => $ fileId , 'is_deleted' => false ] ) -> one ( ) ; if ( $ model ) { if ( $ cleanup ) { foreach ( Yii :: $ app -> storage -> findImages ( [ 'file_id' => $ fileId ] ) as $ imageItem ) { StorageImage :: findOne ( $ imageItem -> id ) -> delete ( ) ; } } $ response = $ model -> delete ( ) ; Yii :: $ app -> storage -> flushArrays ( ) ; return $ response ; } return true ; }
Remove a file from the storage system .
39,739
public static function removeImage ( $ imageId , $ cleanup = false ) { Yii :: $ app -> storage -> flushArrays ( ) ; $ image = Yii :: $ app -> storage -> getImage ( $ imageId ) ; if ( $ cleanup && $ image ) { $ fileId = $ image -> fileId ; foreach ( Yii :: $ app -> storage -> findImages ( [ 'file_id' => $ fileId ] ) as $ imageItem ) { $ storageImage = StorageImage :: findOne ( $ imageItem -> id ) ; if ( $ storageImage ) { $ storageImage -> delete ( ) ; } } } $ file = StorageImage :: findOne ( $ imageId ) ; if ( $ file ) { return $ file -> delete ( ) ; } return false ; }
Remove an image from the storage system and database .
39,740
public static function getImageResolution ( $ filePath , $ throwException = false ) { $ dimensions = @ getimagesize ( Yii :: getAlias ( $ filePath ) ) ; $ width = 0 ; $ height = 0 ; if ( isset ( $ dimensions [ 0 ] ) && isset ( $ dimensions [ 1 ] ) ) { $ width = ( int ) $ dimensions [ 0 ] ; $ height = ( int ) $ dimensions [ 1 ] ; } elseif ( $ throwException ) { throw new Exception ( "Unable to determine the resoltuions of the file $filePath." ) ; } return [ 'width' => $ width , 'height' => $ height , ] ; }
Get the image resolution of a given file path .
39,741
public static function moveFileToFolder ( $ fileId , $ folderId ) { $ file = StorageFile :: findOne ( $ fileId ) ; if ( $ file ) { $ file -> updateAttributes ( [ 'folder_id' => $ folderId ] ) ; Yii :: $ app -> storage -> flushArrays ( ) ; return true ; } return false ; }
Move a storage file to another folder .
39,742
public static function replaceFile ( $ fileName , $ newFileSource , $ newFileName ) { try { Yii :: $ app -> storage -> ensureFileUpload ( $ newFileSource , $ newFileName ) ; } catch ( \ Exception $ e ) { return false ; } return Yii :: $ app -> storage -> fileSystemReplaceFile ( $ fileName , $ newFileSource ) ; }
Replace the source of a file on the webeserver based on new and old source path informations .
39,743
private function isSkippableTable ( $ tableName , array $ filters ) { $ skip = true ; foreach ( $ filters as $ filter ) { $ exclude = false ; if ( substr ( $ filter , 0 , 1 ) == "!" ) { $ exclude = true ; $ skip = false ; $ filter = substr ( $ filter , 1 ) ; } if ( $ filter == $ tableName || StringHelper :: startsWithWildcard ( $ tableName , $ filter ) ) { return $ exclude ; } } return $ skip ; }
Compare the tableName with the given filters .
39,744
public static function findRelations ( $ tableName , $ pkId ) { return self :: find ( ) -> innerJoin ( TagRelation :: tableName ( ) , '{{%admin_tag_relation}}.tag_id={{%admin_tag}}.id' ) -> where ( [ 'pk_id' => $ pkId , 'table_name' => TaggableTrait :: cleanBaseTableName ( $ tableName ) ] ) -> indexBy ( 'name' ) -> all ( ) ; }
Get all primary key assigned tags for a table name .
39,745
public static function findRelationsTable ( $ tableName ) { return self :: find ( ) -> innerJoin ( TagRelation :: tableName ( ) , '{{%admin_tag_relation}}.tag_id={{%admin_tag}}.id' ) -> where ( [ 'table_name' => TaggableTrait :: cleanBaseTableName ( $ tableName ) ] ) -> indexBy ( 'name' ) -> distinct ( ) -> all ( ) ; }
Get all assigned tags for table name .
39,746
public function syncData ( ) { if ( Yii :: $ app -> controller -> interactive && $ this -> getRows ( ) > self :: LARGE_TABLE_PROMPT ) { if ( Console :: confirm ( "{$this->getName()} has {$this->getRows()} entries. Do you want continue table sync?" , true ) === false ) { return ; } } $ sqlMode = $ this -> prepare ( ) ; try { Yii :: $ app -> db -> createCommand ( ) -> truncateTable ( $ this -> getName ( ) ) -> execute ( ) ; $ this -> syncDataInternal ( ) ; } finally { $ this -> cleanup ( $ sqlMode ) ; } }
Sync the data from remote table to local table .
39,747
protected function prepare ( ) { $ sqlMode = null ; if ( Yii :: $ app -> db -> schema instanceof \ yii \ db \ mysql \ Schema ) { Yii :: $ app -> db -> createCommand ( 'SET FOREIGN_KEY_CHECKS = 0;' ) -> execute ( ) ; Yii :: $ app -> db -> createCommand ( 'SET UNIQUE_CHECKS = 0;' ) -> execute ( ) ; $ sqlMode = Yii :: $ app -> db -> createCommand ( 'SELECT @@SQL_MODE;' ) -> queryScalar ( ) ; Yii :: $ app -> db -> createCommand ( 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";' ) -> execute ( ) ; } return $ sqlMode ; }
Prepare database for data sync and set system variables .
39,748
protected function cleanup ( $ sqlMode ) { if ( Yii :: $ app -> db -> schema instanceof \ yii \ db \ mysql \ Schema ) { Yii :: $ app -> db -> createCommand ( 'SET FOREIGN_KEY_CHECKS = 1;' ) -> execute ( ) ; Yii :: $ app -> db -> createCommand ( 'SET UNIQUE_CHECKS = 1;' ) -> execute ( ) ; if ( $ sqlMode !== null ) { Yii :: $ app -> db -> createCommand ( 'SET SQL_MODE=:sqlMode;' , [ ':sqlMode' => $ sqlMode ] ) -> execute ( ) ; } } }
Revert database system variables .
39,749
private function syncDataInternal ( ) { Console :: startProgress ( 0 , $ this -> getOffsetTotal ( ) , 'Fetch: ' . $ this -> getName ( ) . ' ' ) ; $ this -> _contentRowsCount = 0 ; $ dataChunk = [ ] ; for ( $ i = 0 ; $ i < $ this -> getOffsetTotal ( ) ; ++ $ i ) { $ requestData = $ this -> request ( $ i ) ; if ( ! $ requestData ) { continue ; } if ( 0 === $ i % $ this -> build -> syncRequestsCount ) { $ inserted = $ this -> insertData ( $ dataChunk ) ; $ this -> _contentRowsCount += $ inserted ; $ dataChunk = [ ] ; } Console :: updateProgress ( $ i + 1 , $ this -> getOffsetTotal ( ) ) ; $ dataChunk = array_merge ( $ requestData , $ dataChunk ) ; gc_collect_cycles ( ) ; } if ( ! empty ( $ dataChunk ) ) { $ this -> insertData ( $ dataChunk ) ; } Console :: endProgress ( ) ; }
Start the data sync .
39,750
private function request ( $ offset ) { $ curl = new Curl ( ) ; $ curl -> get ( $ this -> build -> requestUrl , [ 'machine' => $ this -> build -> machineIdentifier , 'buildToken' => $ this -> build -> buildToken , 'table' => $ this -> name , 'offset' => $ offset ] ) ; if ( ! $ curl -> error ) { $ response = Json :: decode ( $ curl -> response ) ; $ curl -> close ( ) ; unset ( $ curl ) ; return $ response ; } else { $ this -> build -> command -> outputError ( 'Error while collecting data from server: ' . $ curl -> error_message ) ; } return false ; }
Send request for this table and return the JSON data .
39,751
private function insertData ( $ data ) { $ inserted = Yii :: $ app -> db -> createCommand ( ) -> batchInsert ( $ this -> getName ( ) , $ this -> cleanUpBatchInsertFields ( $ this -> getFields ( ) ) , $ this -> cleanUpMatchRow ( $ data ) ) -> execute ( ) ; return $ inserted ; }
Write the given data to the database .
39,752
public function getPermissionTable ( $ userId ) { if ( $ this -> _permissionTable === null ) { $ this -> _permissionTable = ( new Query ( ) ) -> select ( [ '*' ] ) -> from ( '{{%admin_user_group}}' ) -> innerJoin ( '{{%admin_group_auth}}' , '{{%admin_user_group}}.group_id={{%admin_group_auth}}.group_id' ) -> innerJoin ( '{{%admin_auth}}' , '{{%admin_group_auth}}.auth_id = {{%admin_auth}}.id' ) -> where ( [ '{{%admin_user_group}}.user_id' => $ userId ] ) -> all ( ) ; } return $ this -> _permissionTable ; }
Get all permissions entries for the given User .
39,753
public function getApiTable ( $ userId , $ apiEndpoint ) { $ data = [ ] ; foreach ( $ this -> getPermissionTable ( $ userId ) as $ item ) { if ( $ item [ 'api' ] == $ apiEndpoint && $ item [ 'user_id' ] == $ userId ) { $ data [ ] = $ item ; } } return $ data ; }
Get the data for a given api and user .
39,754
public function getRouteTable ( $ userId , $ route ) { $ data = [ ] ; foreach ( $ this -> getPermissionTable ( $ userId ) as $ item ) { if ( $ item [ 'route' ] == $ route && $ item [ 'user_id' ] == $ userId ) { $ data [ ] = $ item ; } } return $ data ; }
Get the data for a given route and user .
39,755
public function permissionVerify ( $ type , $ permissionWeight ) { $ numbers = [ ] ; switch ( $ type ) { case self :: CAN_CREATE : $ numbers = [ 1 , 4 , 6 , 9 ] ; break ; case self :: CAN_UPDATE : $ numbers = [ 3 , 4 , 8 , 9 ] ; break ; case self :: CAN_DELETE : $ numbers = [ 5 , 6 , 8 , 9 ] ; break ; } return in_array ( $ permissionWeight , $ numbers ) ; }
Verify a permission type against its calculated weight .
39,756
public function matchApi ( $ userId , $ apiEndpoint , $ typeVerification = false ) { $ groups = $ this -> getApiTable ( $ userId , $ apiEndpoint ) ; if ( $ typeVerification === false || $ typeVerification === self :: CAN_VIEW ) { return ( count ( $ groups ) > 0 ) ? true : false ; } foreach ( $ groups as $ row ) { if ( $ this -> permissionVerify ( $ typeVerification , $ this -> permissionWeight ( $ row [ 'crud_create' ] , $ row [ 'crud_update' ] , $ row [ 'crud_delete' ] ) ) ) { return true ; } } return false ; }
See if a User have rights to access this api .
39,757
public function matchRoute ( $ userId , $ route ) { $ groups = $ this -> getRouteTable ( $ userId , $ route ) ; if ( is_array ( $ groups ) && count ( $ groups ) > 0 ) { return true ; } return false ; }
See if the user has permitted the provided route .
39,758
public function getDatabaseAuths ( ) { $ data = [ 'routes' => [ ] , 'apis' => [ ] , ] ; foreach ( ( new Query ( ) ) -> select ( '*' ) -> from ( '{{%admin_auth}}' ) -> all ( ) as $ item ) { if ( empty ( $ item [ 'api' ] ) ) { $ data [ 'routes' ] [ ] = $ item ; } else { $ data [ 'apis' ] [ ] = $ item ; } } return $ data ; }
Returns the current available auth rules inside the admin_auth table splied into routes and apis .
39,759
public function executeCleanup ( array $ data ) { foreach ( $ data as $ rule ) { Yii :: $ app -> db -> createCommand ( ) -> delete ( '{{%admin_auth}}' , 'id=:id' , [ 'id' => $ rule [ 'id' ] ] ) -> execute ( ) ; Yii :: $ app -> db -> createCommand ( ) -> delete ( '{{%admin_group_auth}}' , 'auth_id=:id' , [ 'id' => $ rule [ 'id' ] ] ) -> execute ( ) ; } return true ; }
Execute the data to delete based on an array containing a key id with the corresponding value from the Database .
39,760
public function callbackLoadAllImages ( ) { $ query = ( new Query ( ) ) -> select ( [ 'image_id' => $ this -> imageIdFieldName ] ) -> where ( [ $ this -> refFieldName => $ this -> getItemId ( ) ] ) -> from ( $ this -> refTableName ) ; if ( $ this -> isSortEnabled ( ) ) { $ query -> orderBy ( [ $ this -> sortIndexFieldName => SORT_ASC ] ) ; } $ data = $ query -> all ( ) ; $ images = [ ] ; foreach ( $ data as $ image ) { $ images [ ] = $ this -> getImageArray ( $ image [ 'image_id' ] ) ; } return $ images ; }
Load all images .
39,761
private function getImageArray ( $ imageId ) { $ array = Yii :: $ app -> storage -> getImage ( $ imageId ) -> applyFilter ( MediumCrop :: identifier ( ) ) -> toArray ( ) ; $ array [ 'originalImageId' ] = $ imageId ; return $ array ; }
Get the image array for a given image id .
39,762
public function callbackRemoveFromIndex ( $ imageId ) { return Yii :: $ app -> db -> createCommand ( ) -> delete ( $ this -> refTableName , [ $ this -> imageIdFieldName => ( int ) $ imageId , $ this -> refFieldName => ( int ) $ this -> getItemId ( ) , ] ) -> execute ( ) ; }
Remove a given image id from the index .
39,763
public function callbackAddImageToIndex ( $ fileId ) { $ image = Yii :: $ app -> storage -> addImage ( $ fileId ) ; if ( ! $ image ) { return $ this -> sendError ( "Unable to create image from given file Id." ) ; } Yii :: $ app -> db -> createCommand ( ) -> insert ( $ this -> refTableName , $ this -> prepareInsertFields ( [ $ this -> imageIdFieldName => ( int ) $ image -> id , $ this -> refFieldName => ( int ) $ this -> itemId , ] ) ) -> execute ( ) ; return $ this -> getImageArray ( $ image -> id ) ; }
Generate an image for a given file id and store the image in the index .
39,764
public function callbackChangeSortIndex ( $ new , $ old ) { $ newPos = ( new Query ) -> select ( [ $ this -> sortIndexFieldName ] ) -> from ( $ this -> refTableName ) -> where ( [ $ this -> imageIdFieldName => $ new [ 'originalImageId' ] ] ) -> scalar ( ) ; $ oldPos = ( new Query ) -> select ( [ $ this -> sortIndexFieldName ] ) -> from ( $ this -> refTableName ) -> where ( [ $ this -> imageIdFieldName => $ old [ 'originalImageId' ] ] ) -> scalar ( ) ; $ changeNewPos = Yii :: $ app -> db -> createCommand ( ) -> update ( $ this -> refTableName , [ $ this -> sortIndexFieldName => $ oldPos ] , [ $ this -> imageIdFieldName => $ new [ 'originalImageId' ] , $ this -> refFieldName => $ this -> itemId , ] ) -> execute ( ) ; $ changeOldPos = Yii :: $ app -> db -> createCommand ( ) -> update ( $ this -> refTableName , [ $ this -> sortIndexFieldName => $ newPos ] , [ $ this -> imageIdFieldName => $ old [ 'originalImageId' ] , $ this -> refFieldName => $ this -> itemId , ] ) -> execute ( ) ; return true ; }
Switch position between two images .
39,765
public function prepareInsertFields ( array $ fields ) { if ( $ this -> isSortEnabled ( ) ) { $ fields [ $ this -> sortIndexFieldName ] = $ this -> getMaxSortIndex ( ) + 1 ; } return $ fields ; }
Prepare and parse the insert fields for a given array .
39,766
public function render ( ) { $ html = null ; if ( $ this -> _hint ) { $ html = '<span class="help-button btn btn-icon btn-help" tooltip tooltip-text="' . $ this -> _hint . '" tooltip-position="left"></span>' ; } $ html .= Angular :: directive ( $ this -> type , $ this -> options ) ; return $ html ; }
Render the Angular Object element
39,767
public function getCaption ( ) { if ( $ this -> _caption === null ) { if ( ! Json :: isJson ( $ this -> getKey ( 'caption' , false ) ) ) { $ this -> _caption = $ this -> getKey ( 'caption' ) ; } else { $ this -> _caption = I18n :: findActive ( $ this -> getCaptionArray ( ) ) ; } } return $ this -> _caption ; }
Return the caption text for this file if not defined the item array will be collected
39,768
public function getSource ( $ scheme = false ) { return $ scheme ? Yii :: $ app -> storage -> fileAbsoluteHttpPath ( $ this -> getKey ( 'name_new_compound' ) ) : Yii :: $ app -> storage -> fileHttpPath ( $ this -> getKey ( 'name_new_compound' ) ) ; }
Get the absolute source path to the file location on the webserver .
39,769
public function getLink ( $ scheme = false ) { return Url :: toRoute ( [ '/admin/file/download' , 'id' => $ this -> getId ( ) , 'hash' => $ this -> getHashName ( ) , 'fileName' => $ this -> getName ( ) ] , $ scheme ) ; }
Get the link to a file .
39,770
public function addDummyFile ( array $ config ) { $ keys = [ 'id' , 'is_hidden' , 'is_deleted' , 'folder_id' , 'name_original' , 'name_new' , 'name_new_compound' , 'mime_type' , 'extension' , 'hash_name' , 'hash_file' , 'upload_timestamp' , 'file_size' , 'upload_user_id' , 'caption' ] ; $ item = array_flip ( $ keys ) ; $ data = array_merge ( $ item , $ config ) ; $ this -> _files [ $ data [ 'id' ] ] = $ data ; }
Add a dummy file .
39,771
public function addDummyImage ( array $ config ) { $ keys = [ 'id' , 'file_id' , 'filter_id' , 'resolution_width' , 'resolution_height' ] ; $ item = array_flip ( $ keys ) ; $ data = array_merge ( $ item , $ config ) ; $ this -> _images [ $ data [ 'id' ] ] = $ data ; }
Add dummy image .
39,772
public static function findActive ( ) { if ( self :: $ _langInstanceFindActive === null ) { $ langShortCode = Yii :: $ app -> composition -> getKey ( 'langShortCode' ) ; if ( ! $ langShortCode ) { self :: $ _langInstanceFindActive = self :: getDefault ( ) ; } else { self :: $ _langInstanceFindActive = self :: find ( ) -> where ( [ 'short_code' => $ langShortCode , 'is_deleted' => false ] ) -> asArray ( ) -> one ( ) ; } } return self :: $ _langInstanceFindActive ; }
Get the active langauge array
39,773
public function run ( $ id ) { $ model = $ this -> findModel ( $ id ) ; if ( $ this -> checkAccess ) { call_user_func ( $ this -> checkAccess , $ this -> id , $ model ) ; } if ( ! Yii :: $ app -> adminuser -> identity -> is_api_user ) { $ modelClass = $ this -> modelClass ; $ table = $ modelClass :: tableName ( ) ; $ alias = Yii :: $ app -> adminmenu -> getApiDetail ( $ modelClass :: ngRestApiEndpoint ( ) ) ; UserOnline :: lock ( Yii :: $ app -> adminuser -> id , $ table , $ id , 'lock_admin_edit_crud_item' , [ 'table' => $ alias [ 'alias' ] , 'id' => $ id , 'module' => $ alias [ 'module' ] [ 'alias' ] ] ) ; } return $ model ; }
Return the model for a given resource id .
39,774
protected function flushApiCache ( $ folderId = 0 , $ page = 0 ) { Yii :: $ app -> storage -> flushArrays ( ) ; $ this -> deleteHasCache ( 'storageApiDataFolders' ) ; $ this -> deleteHasCache ( [ 'storageApiDataFiles' , ( int ) $ folderId , ( int ) $ page ] ) ; }
Flush the storage caching data .
39,775
public function actionDataFolders ( ) { return $ this -> getOrSetHasCache ( 'storageApiDataFolders' , function ( ) { $ folders = [ ] ; foreach ( Yii :: $ app -> storage -> findFolders ( ) as $ key => $ folder ) { $ folders [ $ key ] = $ folder -> toArray ( ) ; $ folders [ $ key ] [ 'toggle_open' ] = ( int ) Yii :: $ app -> adminuser -> identity -> setting -> get ( 'foldertree.' . $ folder -> id ) ; $ folders [ $ key ] [ 'subfolder' ] = Yii :: $ app -> storage -> getFolder ( $ folder -> id ) -> hasChild ( ) ; } return $ folders ; } , 0 , new DbDependency ( [ 'sql' => 'SELECT MAX(id) FROM {{%admin_storage_folder}} WHERE is_deleted=false' ] ) ) ; }
Get all folders from the storage component .
39,776
public function actionDataFiles ( $ folderId = 0 , $ search = null ) { $ query = StorageFile :: find ( ) -> select ( [ 'id' , 'name_original' , 'extension' , 'upload_timestamp' , 'file_size' , 'mime_type' ] ) -> where ( [ 'is_hidden' => false , 'is_deleted' => false ] ) -> with ( [ 'images.file' ] ) ; if ( ! empty ( $ search ) ) { $ query -> andFilterWhere ( [ 'or' , [ 'like' , 'name_original' , $ search ] , [ 'like' , 'caption' , $ search ] , [ '=' , 'id' , $ search ] , ] ) ; } else { $ query -> andWhere ( [ 'folder_id' => $ folderId ] ) ; } return new ActiveDataProvider ( [ 'query' => $ query , ] ) ; }
Get all files from the storage container .
39,777
public function actionToggleFileTag ( ) { $ tagId = Yii :: $ app -> request -> getBodyParam ( 'tagId' ) ; $ fileId = Yii :: $ app -> request -> getBodyParam ( 'fileId' ) ; $ file = StorageFile :: findOne ( $ fileId ) ; if ( ! $ file ) { throw new NotFoundHttpException ( "Unable to find the given file to toggle the tag." ) ; } $ relation = TagRelation :: find ( ) -> where ( [ 'table_name' => TaggableTrait :: cleanBaseTableName ( StorageFile :: tableName ( ) ) , 'pk_id' => $ fileId , 'tag_id' => $ tagId ] ) -> one ( ) ; if ( $ relation ) { $ relation -> delete ( ) ; return $ file -> tags ; } $ model = new TagRelation ( ) ; $ model -> table_name = TaggableTrait :: cleanBaseTableName ( StorageFile :: tableName ( ) ) ; $ model -> pk_id = $ fileId ; $ model -> tag_id = $ tagId ; $ model -> save ( ) ; return $ file -> tags ; }
Toggle Tags for a given file .
39,778
public function actionFileInfo ( $ id ) { $ model = StorageFile :: find ( ) -> where ( [ 'id' => $ id ] ) -> with ( [ 'user' , 'images' , 'tags' ] ) -> one ( ) ; if ( ! $ model ) { throw new NotFoundHttpException ( "Unable to find the given storage file." ) ; } return $ model -> toArray ( [ ] , [ 'user' , 'file' , 'images' , 'source' , 'tags' ] ) ; }
Get all storage file informations for a given ID .
39,779
public function actionFile ( $ id ) { $ model = StorageFile :: find ( ) -> where ( [ 'id' => $ id ] ) -> one ( ) ; if ( ! $ model ) { throw new NotFoundHttpException ( "Unable to find the given storage file." ) ; } return $ model ; }
Get file model .
39,780
public function actionImage ( $ id ) { $ model = StorageImage :: find ( ) -> where ( [ 'id' => $ id ] ) -> with ( [ 'file' ] ) -> one ( ) ; if ( ! $ model ) { throw new NotFoundHttpException ( "Unable to find the given storage image." ) ; } return $ model ; }
Get image model .
39,781
public function actionImagesInfo ( ) { $ ids = Yii :: $ app -> request -> getBodyParam ( 'ids' , [ ] ) ; $ ids = array_unique ( $ ids ) ; return new ActiveDataProvider ( [ 'query' => StorageImage :: find ( ) -> where ( [ 'in' , 'id' , $ ids ] ) -> with ( [ 'file' , 'tinyCropImage.file' ] ) , 'pagination' => false , ] ) ; }
A post request with an array of images to load!
39,782
public function actionFilemanagerUpdateCaption ( ) { $ this -> checkRouteAccess ( self :: PERMISSION_ROUTE ) ; $ fileId = Yii :: $ app -> request -> post ( 'id' , false ) ; $ captionsText = Yii :: $ app -> request -> post ( 'captionsText' , false ) ; $ pageId = Yii :: $ app -> request -> post ( 'pageId' , 0 ) ; if ( $ fileId && is_scalar ( $ fileId ) && $ captionsText ) { $ model = StorageFile :: findOne ( $ fileId ) ; if ( $ model ) { $ model -> updateAttributes ( [ 'caption' => I18n :: encode ( $ captionsText ) , ] ) ; $ this -> flushApiCache ( $ model -> folder_id , $ pageId ) ; return true ; } } return false ; }
Update the caption of storage file .
39,783
public function actionImageFilter ( ) { $ this -> checkRouteAccess ( self :: PERMISSION_ROUTE ) ; $ image = Yii :: $ app -> storage -> createImage ( Yii :: $ app -> request -> post ( 'fileId' , null ) , Yii :: $ app -> request -> post ( 'filterId' , null ) ) ; if ( $ image ) { return [ 'error' => false , 'id' => $ image -> id , 'image' => $ image ] ; } return $ this -> sendArrayError ( [ 'error' => true , 'message' => Module :: t ( 'api_storage_image_upload_error' , [ 'error' => 'Unable to create the filter for the given image. Maybe the file source is not readable.' ] ) , ] ) ; }
Upload an image to the filemanager .
39,784
public function actionFileReplace ( ) { $ this -> checkRouteAccess ( self :: PERMISSION_ROUTE ) ; $ fileId = Yii :: $ app -> request -> post ( 'fileId' , false ) ; $ pageId = Yii :: $ app -> request -> post ( 'pageId' , 0 ) ; Yii :: warning ( 'replace request for file id' . $ fileId , __METHOD__ ) ; $ raw = $ _FILES [ 'file' ] ; if ( $ file = Yii :: $ app -> storage -> getFile ( $ fileId ) ) { $ newFileSource = $ raw [ 'tmp_name' ] ; if ( is_uploaded_file ( $ newFileSource ) ) { $ fileData = Yii :: $ app -> storage -> ensureFileUpload ( $ raw [ 'tmp_name' ] , $ raw [ 'name' ] ) ; if ( $ fileData [ 'mimeType' ] != $ file -> mimeType ) { throw new BadRequestHttpException ( "The type must be the same as the original file in order to replace." ) ; } if ( Storage :: replaceFile ( $ file -> systemFileName , $ newFileSource , $ raw [ 'name' ] ) ) { foreach ( StorageImage :: find ( ) -> where ( [ 'file_id' => $ file -> id ] ) -> all ( ) as $ img ) { $ removal = Storage :: removeImage ( $ img -> id , false ) ; } $ model = StorageFile :: findOne ( ( int ) $ fileId ) ; $ fileHash = FileHelper :: md5sum ( $ newFileSource ) ; $ fileSize = @ filesize ( $ newFileSource ) ; $ model -> updateAttributes ( [ 'hash_file' => $ fileHash , 'file_size' => $ fileSize , 'upload_timestamp' => time ( ) , ] ) ; $ this -> flushApiCache ( $ model -> folder_id , $ pageId ) ; return true ; } } } return false ; }
Action to replace a current file with a new .
39,785
public function actionFilemanagerMoveFiles ( ) { $ this -> checkRouteAccess ( self :: PERMISSION_ROUTE ) ; $ toFolderId = Yii :: $ app -> request -> post ( 'toFolderId' , 0 ) ; $ fileIds = Yii :: $ app -> request -> post ( 'fileIds' , [ ] ) ; $ currentPageId = Yii :: $ app -> request -> post ( 'currentPageId' , 0 ) ; $ currentFolderId = Yii :: $ app -> request -> post ( 'currentFolderId' , 0 ) ; $ response = Storage :: moveFilesToFolder ( $ fileIds , $ toFolderId ) ; $ this -> flushApiCache ( $ currentFolderId , $ currentPageId ) ; $ this -> flushApiCache ( $ toFolderId , $ currentPageId ) ; $ this -> flushHasCache ( $ toFolderId , 0 ) ; return $ response ; }
Move files into another folder .
39,786
public function actionFilemanagerRemoveFiles ( ) { $ this -> checkRouteAccess ( self :: PERMISSION_ROUTE ) ; $ pageId = Yii :: $ app -> request -> post ( 'pageId' , 0 ) ; $ folderId = Yii :: $ app -> request -> post ( 'folderId' , 0 ) ; foreach ( Yii :: $ app -> request -> post ( 'ids' , [ ] ) as $ id ) { if ( ! Storage :: removeFile ( $ id ) ) { return false ; } } $ this -> flushApiCache ( $ folderId , $ pageId ) ; return true ; }
Remove files from the storage component .
39,787
public function actionIsFolderEmpty ( $ folderId ) { $ count = StorageFile :: find ( ) -> where ( [ 'folder_id' => $ folderId , 'is_deleted' => false ] ) -> count ( ) ; return [ 'count' => $ count , 'empty' => $ count > 0 ? false : true , ] ; }
Check whether a folder is empty or not in order to delete this folder .
39,788
public function actionFolderDelete ( $ folderId ) { $ this -> checkRouteAccess ( self :: PERMISSION_ROUTE ) ; $ matchingChildFolders = StorageFolder :: find ( ) -> where ( [ 'parent_id' => $ folderId ] ) -> asArray ( ) -> all ( ) ; foreach ( $ matchingChildFolders as $ matchingChildFolder ) { $ this -> actionFolderDelete ( $ matchingChildFolder [ 'id' ] ) ; } $ folderFiles = StorageFile :: find ( ) -> where ( [ 'folder_id' => $ folderId ] ) -> all ( ) ; foreach ( $ folderFiles as $ folderFile ) { $ folderFile -> delete ( ) ; } $ model = StorageFolder :: findOne ( $ folderId ) ; if ( ! $ model ) { return false ; } $ model -> is_deleted = true ; $ this -> flushApiCache ( ) ; return $ model -> update ( ) ; }
delete folder all subfolders and all included files .
39,789
public function actionFolderUpdate ( $ folderId ) { $ this -> checkRouteAccess ( self :: PERMISSION_ROUTE ) ; $ model = StorageFolder :: findOne ( $ folderId ) ; if ( ! $ model ) { return false ; } $ model -> attributes = Yii :: $ app -> request -> post ( ) ; $ this -> flushApiCache ( ) ; return $ model -> update ( ) ; }
Update the folder model data .
39,790
public function actionFolderCreate ( ) { $ this -> checkRouteAccess ( self :: PERMISSION_ROUTE ) ; $ folderName = Yii :: $ app -> request -> post ( 'folderName' , null ) ; $ parentFolderId = Yii :: $ app -> request -> post ( 'parentFolderId' , 0 ) ; $ response = Yii :: $ app -> storage -> addFolder ( $ folderName , $ parentFolderId ) ; $ this -> flushApiCache ( ) ; return $ response ; }
Create a new folder pased on post data .
39,791
public function getRules ( ) { return [ [ 'allow' => true , 'actions' => [ ] , 'roles' => [ '@' ] , 'matchCallback' => function ( $ rule , $ action ) { if ( $ action -> controller -> disablePermissionCheck ) { return true ; } $ route = implode ( '/' , [ $ action -> controller -> module -> id , $ action -> controller -> id , $ action -> id ] ) ; UserOnline :: refreshUser ( $ this -> user -> identity , $ route ) ; return Yii :: $ app -> auth -> matchRoute ( $ this -> user -> id , $ route ) ; } , ] , ] ; }
Returns the rules for the AccessControl filter behavior .
39,792
public function behaviors ( ) { $ behaviors = [ 'access' => [ 'class' => AccessControl :: className ( ) , 'user' => Yii :: $ app -> adminuser , 'rules' => $ this -> getRules ( ) , ] , ] ; if ( ! empty ( $ this -> apiResponseActions ) ) { $ behaviors [ 'negotiator' ] = [ 'class' => ContentNegotiator :: className ( ) , 'only' => $ this -> apiResponseActions , 'formats' => [ 'application/json' => Response :: FORMAT_JSON , ] , ] ; } return $ behaviors ; }
Attach the AccessControl filter behavior for the controler .
39,793
public function getAuthApis ( ) { $ menu = $ this -> getMenu ( ) ; if ( ! $ menu ) { return $ this -> extendPermissionApis ( ) ; } return ArrayHelper :: merge ( $ this -> extendPermissionApis ( ) , $ menu -> getPermissionApis ( ) ) ; }
Get an array with all api routes based on the menu builder .
39,794
public function getAuthRoutes ( ) { $ menu = $ this -> getMenu ( ) ; if ( ! $ menu ) { return $ this -> extendPermissionRoutes ( ) ; } return ArrayHelper :: merge ( $ this -> extendPermissionRoutes ( ) , $ menu -> getPermissionRoutes ( ) ) ; }
Get an array with all routes based on the menu builder .
39,795
public function actionIndex ( ) { $ userId = Yii :: $ app -> adminuser -> id ; UserOnline :: clearList ( $ this -> module -> userIdleTimeout ) ; $ userOnlineModel = UserOnline :: findOne ( [ 'user_id' => Yii :: $ app -> adminuser -> id ] ) ; if ( ! $ userOnlineModel ) { Yii :: $ app -> response -> statusCode = 401 ; return Yii :: $ app -> response -> send ( ) ; } $ this -> getOrSetHasCache ( [ 'timestamp' , 'queue' , 'run' ] , function ( ) { Yii :: $ app -> adminqueue -> run ( false ) ; Config :: set ( Config :: CONFIG_QUEUE_TIMESTAMP , time ( ) ) ; } , 60 * 5 ) ; $ lastKeyStroke = Yii :: $ app -> request -> getBodyParam ( 'lastKeyStroke' ) ; if ( Yii :: $ app -> session -> get ( '__lastKeyStroke' ) != $ lastKeyStroke ) { $ userOnlineModel -> last_timestamp = time ( ) ; $ userOnlineModel -> update ( true , [ 'last_timestamp' ] ) ; } Yii :: $ app -> session -> set ( '__lastKeyStroke' , $ lastKeyStroke ) ; $ seconds = ( time ( ) - $ userOnlineModel -> last_timestamp ) ; $ percentage = round ( ( $ seconds / $ this -> module -> userIdleTimeout ) * 100 ) ; $ offsetPercent = round ( ( 81 / 100 ) * $ percentage ) ; $ strokeOffset = 81 - $ offsetPercent ; $ data = [ 'lastKeyStroke' => $ lastKeyStroke , 'idleSeconds' => $ seconds , 'idleTimeRelative' => round ( ( $ this -> module -> userIdleTimeout - $ seconds ) / 60 ) , 'idlePercentage' => $ percentage , 'idleStrokeDashoffset' => $ strokeOffset , 'useronline' => UserOnline :: getList ( ) , 'forceReload' => Yii :: $ app -> adminuser -> identity -> force_reload , 'locked' => UserOnline :: find ( ) -> select ( [ 'lock_pk' , 'lock_table' , 'last_timestamp' , 'u.firstname' , 'u.lastname' , 'u.id' ] ) -> where ( [ '!=' , 'u.id' , $ userId ] ) -> joinWith ( 'user as u' ) -> createCommand ( ) -> queryAll ( ) , ] ; return $ data ; }
The timestamp action provider informations about currenct only users and if the ui needs to be refreshed .
39,796
public function getModel ( ) { if ( $ this -> _model === null && $ this -> ngRestModelClass !== null ) { $ this -> _model = call_user_func_array ( [ $ this -> ngRestModelClass , 'findOne' ] , $ this -> itemIds ) ; } return $ this -> _model ; }
Get the model object from where the Active Window is attached to .
39,797
public function createCallbackUrl ( $ callback ) { return Url :: to ( [ '/admin/' . $ this -> model -> ngRestApiEndpoint ( ) . '/active-window-callback' , 'activeWindowCallback' => Inflector :: camel2id ( $ callback ) , 'ngrestConfigHash' => $ this -> getConfigHash ( ) , 'activeWindowHash' => $ this -> getActiveWindowHash ( ) , ] , true ) ; }
Create an absolute link to a callback .
39,798
public function getName ( ) { if ( $ this -> _name === null ) { $ this -> _name = ( ( new \ ReflectionClass ( $ this ) ) -> getShortName ( ) ) ; } return $ this -> _name ; }
Get the ActiveWindow name based on its class short name .
39,799
public function getViewFolderName ( ) { if ( $ this -> _viewFolderName === null ) { $ name = $ this -> getName ( ) ; if ( StringHelper :: endsWith ( $ name , $ this -> suffix , false ) ) { $ name = substr ( $ name , 0 , - ( strlen ( $ this -> suffix ) ) ) ; } $ this -> _viewFolderName = strtolower ( $ name ) ; } return $ this -> _viewFolderName ; }
Get the folder name where the views for this ActiveWindow should be stored .