idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
43,700 | public function getTableColumns ( ) : array { $ schema = $ this -> table -> getSchema ( ) ; $ result = [ ] ; foreach ( $ schema -> columns ( ) as $ column ) { if ( in_array ( $ column , CsvMigration :: getRequiredFields ( ) ) ) { continue ; } $ result [ ] = $ column ; } return $ result ; } | Get target module fields . |
43,701 | public static function actionButtons ( ResultSetInterface $ resultSet , Table $ table , array $ data ) : array { $ view = new View ( ) ; list ( $ plugin , $ controller ) = pluginSplit ( $ table -> getRegistryAlias ( ) ) ; foreach ( $ resultSet as $ key => $ entity ) { if ( ! $ entity -> get ( 'model_id' ) ) { $ data [ ... | Add action buttons to response data . |
43,702 | public static function setStatusLabels ( array $ data , int $ index ) : array { $ view = new View ( ) ; $ statusLabels = [ ImportResultsTable :: STATUS_SUCCESS => 'success' , ImportResultsTable :: STATUS_PENDING => 'warning' , ImportResultsTable :: STATUS_FAIL => 'danger' ] ; foreach ( $ data as $ key => $ value ) { $ ... | Response data status labels setter . |
43,703 | protected function _validateUpload ( ) : bool { if ( ! $ this -> request -> getData ( 'file' ) ) { $ this -> flash -> error ( 'Please choose a file to upload.' ) ; return false ; } if ( ! in_array ( $ this -> request -> getData ( 'file.type' ) , $ this -> __supportedMimeTypes ) ) { $ this -> flash -> error ( 'Unable to... | Upload file validation . |
43,704 | protected function _uploadFile ( ) : string { if ( ! is_string ( $ this -> request -> getData ( 'file.name' ) ) ) { return '' ; } if ( ! is_string ( $ this -> request -> getData ( 'file.tmp_name' ) ) ) { return '' ; } $ uploadPath = $ this -> _getUploadPath ( ) ; if ( '' === $ uploadPath ) { return '' ; } $ pathInfo = ... | Upload data file . |
43,705 | protected function _getUploadPath ( ) : string { $ result = Configure :: read ( 'Importer.path' ) ; if ( ! $ result ) { $ result = WWW_ROOT . 'uploads' . DS ; } $ result = rtrim ( $ result , DS ) ; $ result .= DS ; if ( file_exists ( $ result ) ) { return $ result ; } if ( ! mkdir ( $ result , 0777 , true ) ) { $ this ... | Upload path getter . |
43,706 | public function configureEvent ( array $ params = [ ] ) : void { $ params = array_merge ( $ this -> defaultParams , $ params ) ; foreach ( $ params as $ name => $ value ) { $ method = 'set' . ucfirst ( ( string ) $ name ) ; if ( method_exists ( $ this , $ method ) && is_callable ( [ $ this , $ method ] ) ) { $ this -> ... | Configure Event parameters |
43,707 | public function setOrganizer ( string $ email ) : void { if ( '' !== $ email ) { $ this -> event -> setOrganizer ( new Organizer ( $ email , [ 'MAILTO' => $ email ] ) ) ; } } | Set Event organizer |
43,708 | public function setAttendees ( array $ attendees = [ ] ) : void { $ iCalAttendees = new Attendees ( ) ; foreach ( $ attendees as $ email ) { $ iCalAttendees -> add ( "MAILTO:$email" , [ 'ROLE' => 'REQ-PARTICIPANT' , 'PARTSTAT' => 'NEEDS-ACTION' , 'RSVP' => 'TRUE' , ] ) ; } $ this -> event -> setAttendees ( $ iCalAttend... | Set Event attendees |
43,709 | protected function fetchEntity ( string $ id ) : EntityInterface { $ table = $ this -> loadModel ( ) ; Assert :: isInstanceOf ( $ table , Table :: class ) ; $ primaryKey = $ table -> getPrimaryKey ( ) ; if ( ! is_string ( $ primaryKey ) ) { throw new UnsupportedPrimaryKeyException ( ) ; } try { $ entity = $ table -> fi... | Fetches entity from database . |
43,710 | protected function getBatchRedirectUrl ( ) : string { $ result = [ 'plugin' => $ this -> plugin , 'controller' => $ this -> name , 'action' => 'index' ] ; $ currentUrl = $ this -> request -> getEnv ( 'HTTP_ORIGIN' ) . $ this -> request -> getRequestTarget ( ) ; if ( false === strpos ( $ this -> referer ( ) , $ currentU... | Fetch batch redirect url . |
43,711 | public function inModuleList ( string $ item , string $ moduleName , string $ listName ) { try { $ items = ( new ModuleConfig ( ConfigType :: LISTS ( ) , $ moduleName , $ listName ) ) -> parseToArray ( ) ; } catch ( InvalidArgumentException $ e ) { return $ e -> getMessage ( ) ; } $ inactive = $ items [ 'items' ] [ $ i... | Returns true if the passed list item is valid and enabled . |
43,712 | public static function getByType ( string $ type , string $ field , $ table = '' , array $ options = [ ] ) : ConfigInterface { $ configClass = __NAMESPACE__ . '\\' . ucfirst ( $ type ) . 'Config' ; if ( ! class_exists ( $ configClass ) ) { throw new InvalidArgumentException ( "Configuration type [$type] is not supporte... | Get configuration instance by type |
43,713 | public function provide ( $ data = null , array $ options = [ ] ) : array { $ spacer = isset ( $ options [ 'spacer' ] ) ? ( string ) $ options [ 'spacer' ] : ' - ' ; $ flatten = isset ( $ options [ 'flatten' ] ) ? ( bool ) $ options [ 'flatten' ] : true ; list ( $ module , $ list ) = false !== strpos ( $ data , '.' ) ?... | Provide select options |
43,714 | protected function setDefaultFieldOptions ( ) : void { $ table = $ this -> config -> getTable ( ) ; $ field = $ this -> config -> getField ( ) ; $ mc = new ModuleConfig ( ConfigType :: FIELDS ( ) , Inflector :: camelize ( $ table -> getTable ( ) ) ) ; $ config = $ mc -> parseToArray ( ) ; if ( ! empty ( $ config [ $ fi... | Set default field options from config |
43,715 | protected function setDefaultFieldDefinitions ( ) : void { $ table = $ this -> config -> getTable ( ) ; $ field = $ this -> config -> getField ( ) ; $ dbFieldType = $ this -> getDbFieldType ( ) ; $ stubFields = [ $ field => [ 'name' => $ field , 'type' => $ dbFieldType , ] , ] ; if ( $ table instanceof HasFieldsInterfa... | Set default field definitions |
43,716 | protected function setDefaultValue ( ) : void { if ( empty ( $ this -> defaultOptions [ 'default' ] ) ) { return ; } $ eventName = ( string ) EventName :: FIELD_HANDLER_DEFAULT_VALUE ( ) ; $ event = new Event ( $ eventName , $ this , [ 'default' => $ this -> defaultOptions [ 'default' ] ] ) ; $ view = $ this -> config ... | Set default field value |
43,717 | protected function fixOptions ( array $ options = [ ] ) : array { $ result = $ options ; if ( empty ( $ result ) ) { return $ result ; } if ( empty ( $ result [ 'fieldDefinitions' ] ) ) { return $ result ; } if ( ! is_array ( $ result [ 'fieldDefinitions' ] ) ) { return $ result ; } if ( empty ( $ result [ 'fieldDefini... | Fix provided options |
43,718 | public function renderInput ( $ data = '' , array $ options = [ ] ) : string { $ options = array_merge ( $ this -> defaultOptions , $ this -> fixOptions ( $ options ) ) ; $ data = $ this -> getFieldValueFromData ( $ data , $ options ) ; if ( is_resource ( $ data ) ) { $ data = stream_get_contents ( $ data ) ; } if ( em... | Render field input |
43,719 | public function getSearchOptions ( array $ options = [ ] ) : array { $ result = [ ] ; $ options = array_merge ( $ this -> defaultOptions , $ this -> fixOptions ( $ options ) ) ; if ( $ options [ 'fieldDefinitions' ] -> getNonSearchable ( ) ) { return $ result ; } $ options [ 'label' ] = empty ( $ options [ 'label' ] ) ... | Get options for field search |
43,720 | public function renderName ( ) : string { $ label = ! empty ( $ this -> defaultOptions [ 'label' ] ) ? $ this -> defaultOptions [ 'label' ] : '' ; $ renderer = $ this -> config -> getProvider ( 'renderName' ) ; $ renderer = new $ renderer ( $ this -> config ) ; $ result = $ renderer -> provide ( $ label ) ; return $ re... | Render field name |
43,721 | public static function fieldToDb ( CsvField $ csvField ) : array { $ config = ConfigFactory :: getByType ( $ csvField -> getType ( ) , $ csvField -> getName ( ) ) ; $ fieldToDb = $ config -> getProvider ( 'fieldToDb' ) ; $ fieldToDb = new $ fieldToDb ( $ config ) ; $ result = $ fieldToDb -> provide ( $ csvField ) ; ret... | Convert CsvField to one or more DbField instances |
43,722 | public function getDbFieldType ( ) : string { $ dbFieldType = $ this -> config -> getProvider ( 'dbFieldType' ) ; $ dbFieldType = new $ dbFieldType ( $ this -> config ) ; $ dbFieldType = $ dbFieldType -> provide ( ) ; return $ dbFieldType ; } | Get database field type |
43,723 | protected function getFieldValueFromData ( $ data , array $ options ) { $ fieldValue = $ this -> config -> getProvider ( 'fieldValue' ) ; $ fieldValue = new $ fieldValue ( $ this -> config ) ; $ result = $ fieldValue -> provide ( $ data , $ options ) ; return $ result ; } | Get field value from given data |
43,724 | public function autoIncrementFieldValue ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) : void { $ table = $ event -> getSubject ( ) ; if ( ! $ table instanceof Table ) { return ; } $ fields = $ this -> getAutoIncrementFields ( $ table ) ; if ( empty ( $ fields ) ) { return ; } if ( ! $ entity -> i... | Auto - increment reference number . |
43,725 | private function getAutoIncrementFields ( Table $ table ) : array { $ moduleName = Inflector :: camelize ( $ table -> getTable ( ) ) ; $ mc = new ModuleConfig ( ConfigType :: FIELDS ( ) , $ moduleName ) ; $ config = json_encode ( $ mc -> parse ( ) ) ; $ config = false === $ config ? [ ] : json_decode ( $ config , true ... | Retrieves auto - increment fields for specified Module . |
43,726 | private function getAggregatedValue ( array $ options ) { if ( ! $ options [ 'entity' ] instanceof EntityInterface ) { return '' ; } $ config = explode ( ',' , $ options [ 'fieldDefinitions' ] -> getLimit ( ) , 4 ) ; $ configuration = new Configuration ( TableRegistry :: get ( $ config [ 1 ] ) , $ config [ 2 ] ) ; $ co... | Aggregated value getter . |
43,727 | protected function filterFields ( Event $ event ) : void { $ panelActions = ( array ) Configure :: read ( 'CsvMigrations.panels.actions' ) ; $ dynamicPanelActions = ( array ) Configure :: read ( 'CsvMigrations.panels.dynamic_actions' ) ; if ( ! in_array ( $ this -> request -> getParam ( 'action' ) , array_diff ( $ pane... | Filter csv fields . |
43,728 | protected function filterBatchFields ( Event $ event ) : void { $ config = new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ this -> request -> getParam ( 'controller' ) ) ; $ config = json_encode ( $ config -> parse ( ) ) ; $ fields = false === $ config ? [ ] : json_decode ( $ config , true ) ; $ batchFields = ( arra... | Filter batch fields . |
43,729 | public function csv ( Table $ table , string $ path = '' ) : Table { $ this -> factory = new FieldHandlerFactory ( ) ; $ this -> table = $ table ; $ this -> handleCsv ( ) ; return $ this -> table ; } | Method that handles migrations using JSON file . |
43,730 | private function handleCsv ( ) : void { $ tableName = Inflector :: pluralize ( Inflector :: classify ( $ this -> table -> getName ( ) ) ) ; $ mc = new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ tableName ) ; $ data = json_encode ( $ mc -> parse ( ) ) ; if ( false === $ data ) { $ this -> log ( sprintf ( 'No data fo... | Apply changes from the JSON file |
43,731 | public static function getRequiredFields ( bool $ withSchema = false ) : array { return $ withSchema ? self :: $ _requiredFields : array_keys ( self :: $ _requiredFields ) ; } | Required fields getter method . |
43,732 | private function createFromCsv ( array $ data , string $ table ) : void { foreach ( $ data as $ col ) { $ csvField = new CsvField ( $ col ) ; $ dbFields = $ this -> factory -> fieldToDb ( $ csvField , $ table ) ; if ( empty ( $ dbFields ) ) { continue ; } foreach ( $ dbFields as $ dbField ) { $ this -> createColumn ( $... | Create new fields from JSON data . |
43,733 | private function createColumn ( DbField $ dbField ) : void { $ this -> table -> addColumn ( $ dbField -> getName ( ) , $ dbField -> getType ( ) , $ dbField -> getOptions ( ) ) ; if ( 'id' === $ dbField -> getName ( ) ) { $ this -> table -> addPrimaryKey ( [ $ dbField -> getName ( ) , ] ) ; } $ this -> addIndexes ( $ db... | Method used for creating new DB table column . |
43,734 | private function updateColumn ( DbField $ dbField ) : void { $ this -> table -> changeColumn ( $ dbField -> getName ( ) , $ dbField -> getType ( ) , $ dbField -> getOptions ( ) ) ; if ( $ dbField -> getUnique ( ) ) { if ( ! $ this -> table -> hasIndex ( $ dbField -> getName ( ) ) ) { $ this -> table -> addIndex ( [ $ d... | Method used for updating an existing DB table column . |
43,735 | private function addIndexes ( DbField $ dbField , bool $ exists = true ) : void { if ( 'id' === $ dbField -> getName ( ) ) { return ; } $ this -> removeIndexes ( $ dbField , $ exists ) ; $ added = false ; if ( $ dbField -> getUnique ( ) ) { $ added = $ this -> addIndex ( $ dbField , 'unique' , $ exists ) ; } if ( ! $ a... | Adds indexes to specified dbField . |
43,736 | private function removeIndexes ( DbField $ dbField , bool $ exists = true ) : void { if ( ! $ exists ) { return ; } $ this -> table -> removeIndexByName ( $ dbField -> getName ( ) ) ; if ( ! $ dbField -> getUnique ( ) && $ this -> table -> hasIndex ( $ dbField -> getName ( ) ) ) { $ indexName = 'unique_' . $ dbField ->... | Remove column indexes . |
43,737 | private function addIndex ( DbField $ dbField , string $ type , bool $ exists = true ) : bool { if ( empty ( $ type ) ) { return false ; } if ( $ exists && $ this -> table -> hasIndex ( $ dbField -> getName ( ) ) ) { return false ; } $ options = [ ] ; $ options [ 'name' ] = $ type . '_' . $ dbField -> getName ( ) ; if ... | Add column index by type . |
43,738 | protected function _getCsvModules ( ) : array { $ dir = new Folder ( Configure :: read ( 'CsvMigrations.modules.path' ) ) ; $ folders = $ dir -> read ( true ) [ 0 ] ; return ( array ) $ folders ; } | Get CSV module names from defined modules directory . |
43,739 | protected function _getVars ( string $ tableName ) : array { $ table = Inflector :: tableize ( $ tableName ) ; $ name = Inflector :: camelize ( $ tableName ) . $ this -> _getLastModifiedTime ( $ table ) ; return [ $ table , $ name ] ; } | Returns variables for bake template . |
43,740 | protected function _getLastModifiedTime ( string $ tableName ) : string { $ tableName = Inflector :: camelize ( $ tableName ) ; $ mc = new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ tableName ) ; $ path = $ mc -> find ( ) ; $ mtime = filemtime ( $ path ) ; if ( false === $ mtime ) { $ this -> abort ( 'Failed to get... | Get csv file s last modified time . |
43,741 | protected function setAssociation ( string $ type , string $ alias , array $ options ) : void { $ this -> { $ type } ( $ alias , $ options ) ; } | Association setter method . |
43,742 | private function setByTypeRelation ( string $ module , array $ fields ) : void { $ moduleField = $ this -> getModuleRelatedField ( $ fields ) ; if ( is_null ( $ moduleField ) ) { return ; } $ selfrelated = $ this -> getSelfRelated ( $ fields ) ; if ( ! empty ( $ selfrelated ) ) { $ this -> setByTypeSelfRelationField ( ... | Set associations from relation type Modules . |
43,743 | private function setByTypeModuleField ( string $ module , CsvField $ field ) : void { if ( ! $ this -> isRelatedType ( $ field ) ) { return ; } if ( ! in_array ( $ this -> getTableName ( ) , [ $ module , $ field -> getAssocCsvModule ( ) ] ) ) { return ; } $ className = '' ; $ associationType = '' ; if ( $ this -> getTa... | Set associations by field for module type Modules . |
43,744 | private function setByTypeSelfRelationField ( string $ module , array $ fields ) : void { $ first = $ fields [ 0 ] ; $ second = $ fields [ 1 ] ; $ this -> setAssociation ( 'belongsToMany' , static :: generateAssociationName ( $ module , $ first -> getName ( ) ) , [ 'joinTable' => Inflector :: tableize ( $ module ) , 'c... | Set associations for self relation type Modules . |
43,745 | private function setByTypeRelationField ( string $ module , CsvField $ field , CsvField $ moduleField ) : void { if ( ! $ this -> isRelatedType ( $ field ) ) { return ; } if ( $ this -> getTableName ( ) === $ field -> getAssocCsvModule ( ) ) { return ; } if ( $ this -> isFootprintField ( $ field ) || $ this -> isFootpr... | Set associations by field for relation type Modules . |
43,746 | private function isFootprintField ( CsvField $ field ) : bool { if ( ! $ this -> hasBehavior ( 'Footprint' ) ) { return false ; } $ behavior = $ this -> behaviors ( ) -> get ( 'Footprint' ) ; Assert :: isInstanceOf ( $ behavior , Behavior :: class ) ; return in_array ( $ field -> getName ( ) , $ behavior -> getConfig (... | Validates whether the provided field is used in Footprint behavior . |
43,747 | private function setByTypeFileField ( CsvField $ field ) : void { if ( ! in_array ( $ field -> getType ( ) , [ 'files' , 'images' ] ) ) { return ; } $ this -> setAssociation ( 'hasMany' , static :: generateAssociationName ( FileUpload :: FILE_STORAGE_TABLE_NAME , $ field -> getName ( ) ) , [ 'className' => FileUpload :... | Set associations by file type field for module type Modules . |
43,748 | private function getModuleRelatedField ( array $ fields ) : ? CsvField { foreach ( $ fields as $ field ) { if ( $ this -> getTableName ( ) === $ field -> getAssocCsvModule ( ) ) { return $ field ; } } return null ; } | Retrieves current module related field from relation type Modules . |
43,749 | private function getModuleFields ( string $ module ) : array { $ config = ( new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ module ) ) -> parse ( ) ; $ config = json_encode ( $ config ) ; if ( false === $ config ) { return [ ] ; } $ fields = json_decode ( $ config , true ) ; foreach ( $ fields as $ k => $ v ) { $ fi... | Retrieves specified Module fields . |
43,750 | public static function generateAssociationName ( string $ tableName , string $ foreignKey ) : string { list ( $ plugin , $ tableName ) = pluginSplit ( $ tableName ) ; $ plugin = false !== strpos ( $ plugin , '/' ) ? substr ( $ plugin , strpos ( $ plugin , '/' ) + 1 ) : $ plugin ; return Inflector :: camelize ( $ foreig... | Generates unique association name based on Table name and foreign key . |
43,751 | public function checkFields ( string $ module , array $ fields = [ ] ) : void { $ seenFields = [ ] ; foreach ( $ fields as $ field ) { if ( in_array ( $ field [ 'name' ] , $ seenFields ) ) { $ this -> errors [ ] = $ module . " migration specifies field '" . $ field [ 'name' ] . "' more than once" ; continue ; } $ seenF... | Check fields and their types . |
43,752 | private function applyConditionsWithOrder ( QueryInterface $ query ) : QueryInterface { $ table = $ this -> getConfig ( ) -> getTable ( ) ; $ aggregateField = $ table -> aliasField ( $ this -> getConfig ( ) -> getField ( ) ) ; $ query -> select ( $ this -> getConfig ( ) -> getDisplayField ( ) ) -> order ( [ $ aggregate... | If the aggregated field and display field are NOT the same we are using ordering on the aggregated field to retrieve the latest record . |
43,753 | public function sendCalendarEmail ( string $ to , string $ subject , string $ content , array $ eventOptions , string $ config = 'default' ) : array { $ calendar = $ this -> getEventCalendar ( $ eventOptions ) ; $ headers = "Content-Type: text/calendar; charset=utf-8" ; $ headers .= 'Content-Disposition: attachment; fi... | Send email with calendar attachment |
43,754 | protected function getEventCalendar ( array $ eventOptions ) : Calendar { $ event = ( new IcEvent ( $ eventOptions ) ) -> getEvent ( ) ; $ calendar = new IcCalendar ( ) ; $ calendar -> addEvent ( $ event ) ; return $ calendar -> getCalendar ( ) ; } | Get iCal calendar with given event |
43,755 | protected function getDisplayValue ( ) : string { try { $ displayField = $ this -> table -> getDisplayField ( ) ; $ displayValue = $ this -> entity -> get ( $ displayField ) ; $ factory = new FieldHandlerFactory ( ) ; $ result = $ factory -> renderValue ( $ this -> table , $ displayField , $ displayValue , [ 'renderAs'... | Get plain value of the entity display field |
43,756 | public function getEmailSubject ( ) : string { $ result = sprintf ( '%s: %s' , Inflector :: singularize ( $ this -> table -> getAlias ( ) ) , $ this -> getDisplayValue ( ) ) ; if ( ! $ this -> entity -> isNew ( ) ) { $ result = sprintf ( '(Updated) %s' , $ result ) ; } return $ result ; } | Get email subject |
43,757 | public function getEmailContent ( ) : string { $ result = '' ; $ module = Inflector :: singularize ( $ this -> table -> getAlias ( ) ) ; $ displayValue = $ this -> getDisplayValue ( ) ; $ user = $ this -> getUserString ( ) ; $ action = $ this -> entity -> isNew ( ) ? 'created' : 'updated' ; $ result = sprintf ( "%s %s ... | Get email content |
43,758 | public function getEntityUrl ( ) : string { $ result = Router :: url ( [ 'prefix' => false , 'controller' => $ this -> table -> getTable ( ) , 'action' => 'view' , $ this -> entity -> id ] , true ) ; return $ result ; } | Get full URL to the entity view |
43,759 | protected function getUserString ( ) : string { $ result = 'System' ; $ userFields = [ 'name' , 'username' , 'email' , ] ; $ currentUser = User :: getCurrentUser ( ) ; if ( empty ( $ currentUser ) || ! is_array ( $ currentUser ) ) { return $ result ; } foreach ( $ userFields as $ field ) { if ( ! empty ( $ currentUser ... | Get plain value of the current user |
43,760 | protected function getChangelog ( ) : string { $ result = '' ; if ( $ this -> entity -> isNew ( ) ) { return $ result ; } $ fields = $ this -> entity -> extractOriginalChanged ( $ this -> entity -> visibleProperties ( ) ) ; if ( empty ( $ fields ) ) { return $ result ; } foreach ( $ this -> ignoredFields as $ field ) {... | Creates changelog report in string format . |
43,761 | public function findTreeEntities ( QueryInterface $ query , array $ options ) : QueryInterface { $ query = $ query -> where ( [ 'dblist_id' => $ options [ 'listId' ] ] ) -> order ( [ 'lft' => 'asc' ] ) ; $ tree = $ this -> find ( 'treeList' , [ 'spacer' => ' ' ] ) -> toArray ( ) ; foreach ( $ que... | Return all the entities along with the spacer from the treeList . |
43,762 | protected function processImportFile ( Import $ import ) : void { $ this -> out ( 'Processing import file ..' ) ; $ path = ImportUtility :: getProcessedFile ( $ import ) ; if ( file_exists ( $ path ) ) { return ; } $ writer = Writer :: createFromPath ( $ path , 'w+' ) ; $ reader = Reader :: createFromPath ( $ import ->... | Process import file . |
43,763 | protected function _newImport ( ImportsTable $ table , Import $ import , int $ count ) : bool { $ data = [ 'status' => $ table :: STATUS_IN_PROGRESS , 'attempts' => 1 , 'attempted_date' => Time :: now ( ) ] ; $ import = $ table -> patchEntity ( $ import , $ data ) ; $ table -> save ( $ import ) ; $ this -> _run ( $ imp... | New import . |
43,764 | protected function _existingImport ( ImportsTable $ table , Import $ import , int $ count ) : bool { $ result = false ; $ data = [ 'attempted_date' => Time :: now ( ) ] ; if ( $ import -> get ( 'attempts' ) >= ( int ) Configure :: read ( 'Importer.max_attempts' ) ) { $ data [ 'status' ] = $ table :: STATUS_FAIL ; $ imp... | Existing import . |
43,765 | protected function _run ( Import $ import , int $ count ) : void { $ this -> createImportResults ( $ import , $ count ) ; $ this -> out ( 'Importing records ..' ) ; $ progress = $ this -> helper ( 'Progress' ) ; Assert :: isInstanceOf ( $ progress , ProgressHelper :: class ) ; $ progress -> init ( ) ; $ headers = Impor... | Run data import . |
43,766 | protected function createImportResults ( Import $ import , int $ count ) : void { $ this -> out ( 'Preparing records ..' ) ; $ progress = $ this -> helper ( 'Progress' ) ; Assert :: isInstanceOf ( $ progress , ProgressHelper :: class ) ; $ progress -> init ( ) ; $ table = TableRegistry :: get ( 'CsvMigrations.ImportRes... | Import results generator . |
43,767 | protected function _importResult ( Import $ import , array $ headers , int $ rowNumber , array $ data ) : void { $ importTable = TableRegistry :: get ( 'CsvMigrations.ImportResults' ) ; Assert :: isInstanceOf ( $ importTable , ImportResultsTable :: class ) ; $ query = $ importTable -> find ( 'all' ) -> enableHydration ... | Import row . |
43,768 | protected function _prepareData ( Import $ import , array $ headers , array $ data ) : array { $ result = [ ] ; $ options = $ import -> get ( 'options' ) ; $ flipped = array_flip ( $ headers ) ; foreach ( $ options [ 'fields' ] as $ field => $ params ) { if ( empty ( $ params [ 'column' ] ) && empty ( $ params [ 'defau... | Prepare row data . |
43,769 | protected function _processData ( Table $ table , array $ csvFields , array $ data ) : array { $ schema = $ table -> getSchema ( ) ; foreach ( $ data as $ field => $ value ) { if ( ! empty ( $ csvFields ) && in_array ( $ field , array_keys ( $ csvFields ) ) ) { switch ( $ csvFields [ $ field ] -> getType ( ) ) { case '... | Process row data . |
43,770 | protected function _findRelatedRecord ( Table $ table , string $ field , string $ value ) : string { $ csvField = FieldUtility :: getCsvField ( $ table , $ field ) ; if ( null !== $ csvField && 'related' === $ csvField -> getType ( ) ) { $ relatedTable = ( string ) $ csvField -> getLimit ( ) ; $ value = $ this -> _find... | Fetch related record id if found otherwise return initial value . |
43,771 | protected function _findListValue ( RepositoryInterface $ table , string $ listName , string $ value ) : string { $ options = FieldUtility :: getList ( sprintf ( '%s.%s' , $ table -> getAlias ( ) , $ listName ) , true ) ; foreach ( $ options as $ val => $ params ) { if ( $ val !== $ value ) { continue ; } return $ val ... | Fetch list value . |
43,772 | protected function _importFail ( ImportResult $ entity , array $ errors ) : bool { $ table = TableRegistry :: get ( 'CsvMigrations.ImportResults' ) ; Assert :: isInstanceOf ( $ table , ImportResultsTable :: class ) ; $ entity -> set ( 'status' , $ table :: STATUS_FAIL ) ; $ message = sprintf ( $ table :: STATUS_FAIL_ME... | Mark import result as failed . |
43,773 | protected function _importSuccess ( ImportResult $ importResult , EntityInterface $ entity ) : bool { $ table = TableRegistry :: get ( 'CsvMigrations.ImportResults' ) ; Assert :: isInstanceOf ( $ table , ImportResultsTable :: class ) ; $ importResult -> set ( 'model_id' , $ entity -> get ( 'id' ) ) ; $ importResult -> ... | Mark import result as successful . |
43,774 | public static function fromCsvField ( CsvField $ csvField ) : DbField { return new self ( $ csvField -> getName ( ) , $ csvField -> getType ( ) , $ csvField -> getLimit ( ) , $ csvField -> getRequired ( ) , $ csvField -> getNonSearchable ( ) , $ csvField -> getUnique ( ) ) ; } | Construct a new instance from CsvField |
43,775 | protected function setDefaultOptions ( ) : void { $ type = $ this -> getType ( ) ; if ( ! empty ( $ this -> defaultOptions [ $ type ] ) ) { $ this -> options = $ this -> defaultOptions [ $ type ] ; } } | Populate options with defaults |
43,776 | protected function setType ( string $ type ) : void { if ( empty ( $ type ) ) { throw new InvalidArgumentException ( __CLASS__ . ': Empty field type is not allowed' ) ; } if ( ! in_array ( $ type , array_keys ( $ this -> defaultOptions ) ) ) { throw new InvalidArgumentException ( __CLASS__ . ': Unsupported field type: ... | Field type setter . |
43,777 | public function getLimit ( ) { $ result = null ; if ( isset ( $ this -> options [ 'limit' ] ) ) { $ result = $ this -> options [ 'limit' ] ; } return $ result ; } | Field limit getter . |
43,778 | public function getModulesWithoutRelations ( array $ modules ) : array { $ result = [ ] ; foreach ( $ modules as $ moduleName => $ module ) { if ( isset ( $ module [ 'relations' ] ) && is_array ( $ module [ 'relations' ] ) && ! empty ( $ module [ 'relations' ] ) ) { continue ; } $ result [ ] = $ moduleName ; } return $... | Return a list of module names that do not have relations . |
43,779 | protected function getCSVModuleAttr ( string $ moduleName ) : array { if ( empty ( $ this -> modules [ $ moduleName ] ) ) { return [ ] ; } return $ this -> modules [ $ moduleName ] ; } | Get all the csv module s properties |
43,780 | protected function getFieldValueBasedOnType ( string $ type , string $ moduleName = '' , string $ listName = '' ) { $ faker = Factory :: create ( ) ; $ value = null ; switch ( $ type ) { case 'uuid' : $ value = $ faker -> unique ( ) -> uuid ; break ; case 'url' : $ value = $ faker -> url ; break ; case 'time' : $ value... | Get field value based on type . |
43,781 | protected function getCombinedFieldValueBasedOnType ( string $ type , string $ moduleName , string $ fieldName ) : array { $ values = [ ] ; if ( strpos ( $ type , 'money' ) !== false ) { $ values [ $ fieldName . '_amount' ] = $ this -> getFieldValueBasedOnType ( 'decimal' , $ moduleName ) ; $ values [ $ fieldName . '_c... | if the type is money metric will return the multifield values based on the type . |
43,782 | protected function getModuleIds ( string $ moduleName ) : array { $ table = TableRegistry :: get ( $ moduleName ) ; $ query = $ table -> find ( ) -> limit ( 100 ) -> select ( $ table -> getPrimaryKey ( ) ) ; $ result = [ ] ; foreach ( $ query -> all ( ) as $ entity ) { $ result [ ] = $ entity -> get ( $ table -> getPri... | Get Module ids in an array . |
43,783 | protected function checkModuleRelations ( array $ modules ) : array { $ modulesWithRelations = [ ] ; foreach ( $ modules as $ name => $ module ) { $ module [ 'relations' ] = [ ] ; foreach ( $ module as $ field ) { if ( empty ( $ field [ 'type' ] ) ) { continue ; } if ( strpos ( $ field [ 'type' ] , 'related' ) !== fals... | Check module relations . |
43,784 | protected function getModuleCsvData ( array $ modules ) : array { $ csvFiles = [ ] ; foreach ( $ modules as $ module ) { $ mc = new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ module ) ; $ config = json_encode ( $ mc -> parse ( ) ) ; if ( false === $ config ) { continue ; } $ config = json_decode ( $ config , true )... | Get module csv data . |
43,785 | protected function populateDataInModule ( string $ moduleName ) : void { if ( '' === $ moduleName ) { return ; } if ( in_array ( $ moduleName , $ this -> skipModules ) ) { return ; } $ module = $ this -> getCSVModuleAttr ( $ moduleName ) ; if ( empty ( $ module ) ) { return ; } $ table = TableRegistry :: get ( $ module... | Insert data into module . |
43,786 | public function isCombinedField ( string $ type ) : bool { $ result = false ; if ( strpos ( $ type , 'money' ) !== false || strpos ( $ type , 'metric' ) !== false ) { $ result = true ; } return $ result ; } | Checks if the type is money or metric . |
43,787 | protected function createRelationIndex ( array $ modules ) : array { $ index = [ ] ; foreach ( $ modules as $ moduleName => $ module ) { if ( ! isset ( $ module [ 'relations' ] ) ) { $ index [ $ moduleName ] = [ ] ; continue ; } if ( ! is_array ( $ module [ 'relations' ] ) ) { $ index [ $ moduleName ] = [ ] ; continue ... | Create relation index between modules . |
43,788 | protected function checkHierarchyForModule ( string $ moduleName , array $ index ) : void { if ( '' === $ moduleName ) { return ; } if ( in_array ( $ moduleName , $ this -> stack ) ) { return ; } $ this -> stack [ ] = $ moduleName ; if ( in_array ( $ moduleName , $ this -> modulesPolpulatedWithData ) ) { return ; } if ... | Check the hierarchy for each module recursively and populate data . |
43,789 | public function getOptionParser ( ) { $ parser = new ConsoleOptionParser ( 'console' ) ; $ parser -> setDescription ( 'Validate modules configuration' ) ; $ parser -> addArgument ( 'modules' , [ 'help' => 'Comma-separated list of modules to validate. All will be checked if omitted.' , ] ) ; $ parser -> addOption ( 'no... | Set shell description and command line options |
43,790 | public function main ( string $ modules = '' ) { $ this -> info ( 'Checking modules configuration' ) ; $ this -> hr ( ) ; $ this -> modules = Utility :: getModules ( ) ; $ this -> skipWarnings = ( bool ) $ this -> param ( 'no-warnings' ) ; if ( empty ( $ this -> modules ) ) { $ this -> warn ( 'Did not find any modules'... | Main method for shell execution |
43,791 | protected function validateModules ( array $ modules ) : int { $ result = 0 ; foreach ( $ modules as $ module ) { $ this -> info ( "Checking module $module" , 2 ) ; $ moduleResult = $ this -> runModuleChecks ( $ module ) ; $ result += count ( $ moduleResult [ 'errors' ] ) ; if ( ! $ this -> skipWarnings ) { $ this -> p... | Validate a given list of modules |
43,792 | protected function runModuleChecks ( string $ module ) : array { $ result = [ 'errors' => [ ] , 'warnings' => [ ] , ] ; if ( ! in_array ( $ module , $ this -> modules ) ) { $ result [ 'errors' ] [ ] = "$module is not a known module" ; return $ result ; } $ checks = Check :: getList ( $ module ) ; if ( empty ( $ checks ... | Run validation checks for a given module |
43,793 | protected function printMessages ( string $ type , array $ messages = [ ] ) : void { $ this -> out ( '' ) ; $ plural = Inflector :: pluralize ( $ type ) ; if ( empty ( $ messages ) ) { $ this -> success ( "No $plural found in module." ) ; return ; } $ messages = array_unique ( $ messages ) ; $ plural = ucfirst ( $ plur... | Print messages of a given type |
43,794 | public function importDownload ( string $ id , string $ type = 'original' ) : Response { $ table = TableRegistry :: get ( 'CsvMigrations.Imports' ) ; $ entity = $ table -> get ( $ id ) ; Assert :: isInstanceOf ( $ entity , Import :: class ) ; $ path = $ entity -> get ( 'filename' ) ; if ( 'processed' === $ type ) { $ p... | Import download action . |
43,795 | public static function getIcon ( string $ key , string $ value ) : string { $ currenciesList = Configure :: readOrFail ( 'Currencies.list' ) ; if ( ! array_key_exists ( $ key , $ currenciesList ) ) { return $ value ; } return sprintf ( static :: ICON_HTML , $ currenciesList [ $ key ] [ 'description' ] , $ currenciesLis... | Get Icon html |
43,796 | public static function isValidList ( string $ list , string $ module = '' ) : bool { if ( strpos ( $ list , '.' ) !== false ) { list ( $ module , $ list ) = explode ( '.' , $ list , 2 ) ; } $ listItems = null ; try { $ mc = new ModuleConfig ( ConfigType :: LISTS ( ) , $ module , $ list , [ 'cacheSkip' => true ] ) ; $ c... | Check if the given list is valid |
43,797 | public static function isRealModuleField ( string $ module , string $ field ) : bool { $ fields = self :: getRealModuleFields ( $ module ) ; if ( empty ( $ fields ) ) { return true ; } return in_array ( $ field , $ fields ) ; } | Check if the field is defined in the module migration |
43,798 | public static function getRealModuleFields ( string $ module , bool $ validate = true ) : array { $ moduleFields = [ ] ; $ mc = new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ module , null , [ 'cacheSkip' => true ] ) ; $ mc -> setParser ( new Parser ( $ mc -> createSchema ( ) , [ 'validate' => $ validate ] ) ) ; $ ... | Returns a list of fields defined in migration . json . |
43,799 | public static function isRealRelationField ( string $ module , string $ field ) : bool { $ fields = self :: getRealRelationFields ( $ module ) ; if ( empty ( $ fields ) ) { return false ; } return in_array ( $ field , $ fields ) ; } | Check if the field is defined in the relation fields list |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.