idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
49,700 | public static function addressFromBytes ( array $ bytes ) { $ result = null ; if ( $ result === null ) { $ result = Address \ IPv4 :: fromBytes ( $ bytes ) ; } if ( $ result === null ) { $ result = Address \ IPv6 :: fromBytes ( $ bytes ) ; } return $ result ; } | Convert a byte array to an address instance . |
49,701 | public static function rangeFromString ( $ range ) { $ result = null ; if ( $ result === null ) { $ result = Range \ Subnet :: fromString ( $ range ) ; } if ( $ result === null ) { $ result = Range \ Pattern :: fromString ( $ range ) ; } if ( $ result === null ) { $ result = Range \ Single :: fromString ( $ range ) ; } return $ result ; } | Parse an IP range string . |
49,702 | public static function rangeFromBoundaries ( $ from , $ to ) { $ result = null ; $ invalid = false ; foreach ( array ( 'from' , 'to' ) as $ param ) { if ( ! ( $ $ param instanceof AddressInterface ) ) { $ $ param = ( string ) $ $ param ; if ( $ $ param === '' ) { $ $ param = null ; } else { $ $ param = static :: addressFromString ( $ $ param ) ; if ( $ $ param === null ) { $ invalid = true ; } } } } if ( $ invalid === false ) { $ result = static :: rangeFromBoundaryAddresses ( $ from , $ to ) ; } return $ result ; } | Create a Range instance starting from its boundaries . |
49,703 | public static function fromBytes ( array $ bytes ) { $ result = null ; if ( count ( $ bytes ) === 16 ) { $ address = '' ; for ( $ i = 0 ; $ i < 16 ; ++ $ i ) { if ( $ i !== 0 && $ i % 2 === 0 ) { $ address .= ':' ; } $ byte = $ bytes [ $ i ] ; if ( is_int ( $ byte ) && $ byte >= 0 && $ byte <= 255 ) { $ address .= sprintf ( '%02x' , $ byte ) ; } else { $ address = null ; break ; } } if ( $ address !== null ) { $ result = new static ( $ address ) ; } } return $ result ; } | Parse an array of bytes and returns an IPv6 instance if the array is valid or null otherwise . |
49,704 | public static function fromWords ( array $ words ) { $ result = null ; if ( count ( $ words ) === 8 ) { $ chunks = array ( ) ; for ( $ i = 0 ; $ i < 8 ; ++ $ i ) { $ word = $ words [ $ i ] ; if ( is_int ( $ word ) && $ word >= 0 && $ word <= 0xffff ) { $ chunks [ ] = sprintf ( '%04x' , $ word ) ; } else { $ chunks = null ; break ; } } if ( $ chunks !== null ) { $ result = new static ( implode ( ':' , $ chunks ) ) ; } } return $ result ; } | Parse an array of words and returns an IPv6 instance if the array is valid or null otherwise . |
49,705 | public function getWords ( ) { if ( $ this -> words === null ) { $ this -> words = array_map ( function ( $ chunk ) { return hexdec ( $ chunk ) ; } , explode ( ':' , $ this -> longAddress ) ) ; } return $ this -> words ; } | Get the word list of the IP address . |
49,706 | public function findSources ( string $ fieldType , array $ attributes , string $ indexFrom , string $ indexTo ) : array { foreach ( $ attributes as $ key => $ attribute ) { if ( $ key === 'source' ) { $ attributes [ $ key ] = $ this -> getSource ( $ fieldType , $ attribute , $ indexFrom , $ indexTo ) ; } elseif ( $ key === 'sources' ) { $ attributes [ $ key ] = $ this -> getSources ( $ fieldType , $ attribute , $ indexFrom , $ indexTo ) ; } elseif ( is_array ( $ attribute ) ) { $ attributes [ $ key ] = $ this -> findSources ( $ fieldType , $ attribute , $ indexFrom , $ indexTo ) ; } } return $ attributes ; } | Recursively find sources in definition attributes . |
49,707 | public function getSources ( string $ fieldType , $ sources , string $ indexFrom , string $ indexTo ) { $ mappedSources = $ sources ; if ( is_array ( $ sources ) ) { $ mappedSources = [ ] ; $ sources = array_filter ( $ sources ) ; foreach ( $ sources as $ source ) { $ mappedSources [ ] = $ this -> getSource ( $ fieldType , $ source , $ indexFrom , $ indexTo ) ; } } return $ mappedSources ; } | Get sources based on the indexFrom attribute and return them with the indexTo attribute . |
49,708 | private function getFolderByVolumeId ( int $ volumeId ) : VolumeFolder { return $ this -> mockFolder ? $ this -> mockFolder : VolumeFolder :: findOne ( [ 'volumeId' => $ volumeId ] ) ; } | Get folder by volume id |
49,709 | public static function replaceEnvVariables ( $ yaml ) : string { $ matches = null ; preg_match_all ( '/%\w+%/' , $ yaml , $ matches ) ; $ originalValues = $ matches [ 0 ] ; $ replaceValues = [ ] ; foreach ( $ originalValues as $ match ) { $ envVariable = substr ( $ match , 1 , - 1 ) ; $ envValue = getenv ( $ envVariable ) ; if ( ! $ envValue ) { $ envVariable = strtoupper ( $ envVariable ) ; $ envVariable = 'SCHEMATIC_' . $ envVariable ; $ envValue = getenv ( $ envVariable ) ; if ( ! $ envValue ) { throw new Exception ( "Schematic environment variable not set: {$envVariable}" ) ; } } $ replaceValues [ ] = $ envValue ; } return str_replace ( $ originalValues , $ replaceValues , $ yaml ) ; } | Replace placeholders with enviroment variables . |
49,710 | public static function parseYamlFile ( $ file ) : array { if ( file_exists ( $ file ) ) { $ data = file_get_contents ( $ file ) ; if ( ! empty ( $ data ) ) { $ data = static :: replaceEnvVariables ( $ data ) ; return Yaml :: parse ( $ data ) ; } } return [ ] ; } | Read yaml file and parse content . |
49,711 | private function clearSiteCaches ( ) { $ obj = Craft :: $ app -> sites ; $ refObject = new \ ReflectionObject ( $ obj ) ; if ( $ refObject -> hasProperty ( '_sitesById' ) ) { $ refProperty1 = $ refObject -> getProperty ( '_sitesById' ) ; $ refProperty1 -> setAccessible ( true ) ; $ refProperty1 -> setValue ( $ obj , null ) ; } if ( $ refObject -> hasProperty ( '_sitesByHandle' ) ) { $ refProperty2 = $ refObject -> getProperty ( '_sitesByHandle' ) ; $ refProperty2 -> setAccessible ( true ) ; $ refProperty2 -> setValue ( $ obj , null ) ; } $ obj -> init ( ) ; } | Reset craft site service sites cache using reflection . |
49,712 | private function clearEmptyGroups ( ) { foreach ( Craft :: $ app -> sites -> getAllGroups ( ) as $ group ) { if ( count ( $ group -> getSites ( ) ) == 0 ) { Craft :: $ app -> sites -> deleteGroup ( $ group ) ; } } } | Clear empty sute groups |
49,713 | public function actionIndex ( ) : int { $ dataTypes = $ this -> getDataTypes ( ) ; $ definitions = [ ] ; $ overrideData = Data :: parseYamlFile ( $ this -> overrideFile ) ; $ this -> disableLogging ( ) ; try { if ( $ this -> getStorageType ( ) === self :: SINGLE_FILE ) { $ definitions = $ this -> importDefinitionsFromFile ( $ overrideData ) ; $ this -> importFromDefinitions ( $ dataTypes , $ definitions ) ; Schematic :: info ( 'Loaded schema from ' . $ this -> file ) ; } if ( $ this -> getStorageType ( ) === self :: MULTIPLE_FILES ) { $ definitions = $ this -> importDefinitionsFromDirectory ( $ overrideData ) ; $ this -> importFromDefinitions ( $ dataTypes , $ definitions ) ; Schematic :: info ( 'Loaded schema from ' . $ this -> path ) ; } return 0 ; } catch ( \ Exception $ e ) { Schematic :: error ( $ e -> getMessage ( ) ) ; return 1 ; } } | Imports the Craft datamodel . |
49,714 | private function importDefinitionsFromFile ( array $ overrideData ) : array { if ( ! file_exists ( $ this -> file ) ) { throw new \ Exception ( 'File not found: ' . $ this -> file ) ; } $ definitions = Data :: parseYamlFile ( $ this -> file ) ; return array_replace_recursive ( $ definitions , $ overrideData ) ; } | Import definitions from file |
49,715 | private function importDefinitionsFromDirectory ( array $ overrideData ) { if ( ! file_exists ( $ this -> path ) ) { throw new \ Exception ( 'Directory not found: ' . $ this -> path ) ; } $ schemaFiles = preg_grep ( '~\.(yml)$~' , scandir ( $ this -> path ) ) ; foreach ( $ schemaFiles as $ fileName ) { $ schemaStructure = explode ( '.' , $ this -> fromSafeFileName ( $ fileName ) ) ; $ dataTypeHandle = $ schemaStructure [ 0 ] ; $ recordName = $ schemaStructure [ 1 ] ; $ definition = Data :: parseYamlFile ( $ this -> path . $ fileName ) ; if ( isset ( $ overrideData [ $ dataTypeHandle ] [ $ recordName ] ) ) { $ definition = array_replace_recursive ( $ definition , $ overrideData [ $ dataTypeHandle ] [ $ recordName ] ) ; } $ definitions [ $ dataTypeHandle ] [ $ recordName ] = $ definition ; } return $ definitions ; } | Import definitions from directory |
49,716 | private function importFromDefinitions ( array $ dataTypes , array $ definitions ) { foreach ( $ dataTypes as $ dataTypeHandle ) { $ dataType = $ this -> module -> getDataType ( $ dataTypeHandle ) ; if ( null == $ dataType ) { continue ; } $ mapper = $ dataType -> getMapperHandle ( ) ; if ( ! $ this -> module -> checkMapper ( $ mapper ) ) { continue ; } Schematic :: info ( 'Importing ' . $ dataTypeHandle ) ; Schematic :: $ force = $ this -> force ; if ( array_key_exists ( $ dataTypeHandle , $ definitions ) && is_array ( $ definitions [ $ dataTypeHandle ] ) ) { $ records = $ dataType -> getRecords ( ) ; try { $ this -> module -> $ mapper -> import ( $ definitions [ $ dataTypeHandle ] , $ records ) ; $ dataType -> afterImport ( ) ; } catch ( WrongEditionException $ e ) { Schematic :: error ( 'Craft Pro is required for datatype ' . $ dataTypeHandle ) ; } } } } | Import from definitions . |
49,717 | private function getAllMappedPermissions ( ) : array { $ mappedPermissions = [ ] ; foreach ( Craft :: $ app -> userPermissions -> getAllPermissions ( ) as $ permissions ) { $ mappedPermissions = array_merge ( $ mappedPermissions , $ this -> getMappedPermissions ( $ permissions ) ) ; } return $ mappedPermissions ; } | Get a mapping of all permissions from lowercase to camelcase savePermissions only accepts camelcase . |
49,718 | private function getMappedPermissions ( array $ permissions ) : array { $ mappedPermissions = [ ] ; foreach ( $ permissions as $ permission => $ options ) { $ mappedPermissions [ strtolower ( $ permission ) ] = $ permission ; if ( is_array ( $ options ) && array_key_exists ( 'nested' , $ options ) ) { $ mappedPermissions = array_merge ( $ mappedPermissions , $ this -> getMappedPermissions ( $ options [ 'nested' ] ) ) ; } } return $ mappedPermissions ; } | Recursive function to get mapped permissions . |
49,719 | protected function applyIncludes ( $ dataTypes ) : array { $ inclusions = explode ( ',' , $ this -> include ) ; $ invalidIncludes = array_diff ( $ inclusions , $ dataTypes ) ; if ( count ( $ invalidIncludes ) > 0 ) { $ errorMessage = 'WARNING: Invalid include(s)' ; $ errorMessage .= ': ' . implode ( ', ' , $ invalidIncludes ) . '.' . PHP_EOL ; $ errorMessage .= ' Valid inclusions are ' . implode ( ', ' , $ dataTypes ) ; Schematic :: warning ( $ errorMessage ) ; } return array_intersect ( $ dataTypes , $ inclusions ) ; } | Apply given includes . |
49,720 | protected function applyExcludes ( array $ dataTypes ) : array { $ exclusions = explode ( ',' , $ this -> exclude ) ; $ invalidExcludes = array_diff ( $ exclusions , $ dataTypes ) ; if ( count ( $ invalidExcludes ) > 0 ) { $ errorMessage = 'WARNING: Invalid exlude(s)' ; $ errorMessage .= ': ' . implode ( ', ' , $ invalidExcludes ) . '.' . PHP_EOL ; $ errorMessage .= ' Valid exclusions are ' . implode ( ', ' , $ dataTypes ) ; Schematic :: warning ( $ errorMessage ) ; } return array_diff ( $ dataTypes , $ exclusions ) ; } | Apply given excludes . |
49,721 | public function afterImport ( ) { $ obj = Craft :: $ app -> sections ; $ refObject = new \ ReflectionObject ( $ obj ) ; if ( $ refObject -> hasProperty ( '_editableSectionIds' ) ) { $ refProperty1 = $ refObject -> getProperty ( '_editableSectionIds' ) ; $ refProperty1 -> setAccessible ( true ) ; $ refProperty1 -> setValue ( $ obj , $ obj -> getAllSectionIds ( ) ) ; } } | Reset craft editable sections cache using reflection . |
49,722 | private function resetCraftMatrixServiceBlockTypesCache ( ) { $ obj = Craft :: $ app -> matrix ; $ refObject = new \ ReflectionObject ( $ obj ) ; if ( $ refObject -> hasProperty ( '_fetchedAllBlockTypesForFieldId' ) ) { $ refProperty1 = $ refObject -> getProperty ( '_fetchedAllBlockTypesForFieldId' ) ; $ refProperty1 -> setAccessible ( true ) ; $ refProperty1 -> setValue ( $ obj , false ) ; } } | Reset craft matrix service block types cache using reflection . |
49,723 | private function resetCraftMatrixFieldBlockTypesCache ( Model $ record ) { $ obj = $ record ; $ refObject = new \ ReflectionObject ( $ obj ) ; if ( $ refObject -> hasProperty ( '_blockTypes' ) ) { $ refProperty1 = $ refObject -> getProperty ( '_blockTypes' ) ; $ refProperty1 -> setAccessible ( true ) ; $ refProperty1 -> setValue ( $ obj , null ) ; } } | Reset craft matrix field block types cache using reflection . |
49,724 | private function getMappedSettings ( array $ settings , $ fromIndex , $ toIndex ) { $ mappedSettings = [ 'sourceOrder' => [ ] , 'sources' => [ ] ] ; if ( isset ( $ settings [ 'sourceOrder' ] ) ) { foreach ( $ settings [ 'sourceOrder' ] as $ row ) { if ( 'key' == $ row [ 0 ] ) { $ row [ 1 ] = $ this -> getSource ( '' , $ row [ 1 ] , $ fromIndex , $ toIndex ) ; } $ mappedSettings [ 'sourceOrder' ] [ ] = $ row ; } } if ( isset ( $ settings [ 'sources' ] ) ) { foreach ( $ settings [ 'sources' ] as $ source => $ sourceSettings ) { $ mappedSource = $ this -> getSource ( '' , $ source , $ fromIndex , $ toIndex ) ; $ mappedSettings [ 'sources' ] [ $ mappedSource ] = [ 'tableAttributes' => $ this -> getSources ( '' , $ sourceSettings [ 'tableAttributes' ] , $ fromIndex , $ toIndex ) , ] ; } } return $ mappedSettings ; } | Get mapped element index settings converting source ids to handles or back again . |
49,725 | public function import ( array $ definitions , array $ records , array $ defaultAttributes = [ ] , $ persist = true ) : array { $ imported = [ ] ; $ recordsByHandle = $ this -> getRecordsByHandle ( $ records ) ; foreach ( $ definitions as $ handle => $ definition ) { $ modelClass = $ definition [ 'class' ] ; $ converter = Craft :: $ app -> controller -> module -> getConverter ( $ modelClass ) ; if ( $ converter ) { $ record = $ this -> findOrNewRecord ( $ recordsByHandle , $ definition , $ handle ) ; if ( $ converter -> getRecordDefinition ( $ record ) === $ definition ) { Schematic :: info ( '- Skipping ' . get_class ( $ record ) . ' ' . $ handle ) ; } else { $ converter -> setRecordAttributes ( $ record , $ definition , $ defaultAttributes ) ; if ( $ persist ) { Schematic :: info ( '- Saving ' . get_class ( $ record ) . ' ' . $ handle ) ; if ( ! $ converter -> saveRecord ( $ record , $ definition ) ) { Schematic :: importError ( $ record , $ handle ) ; } } } $ imported [ ] = $ record ; } unset ( $ recordsByHandle [ $ handle ] ) ; } if ( Schematic :: $ force && $ persist ) { foreach ( $ recordsByHandle as $ handle => $ record ) { $ modelClass = get_class ( $ record ) ; Schematic :: info ( '- Deleting ' . get_class ( $ record ) . ' ' . $ handle ) ; $ converter = Craft :: $ app -> controller -> module -> getConverter ( $ modelClass ) ; $ converter -> deleteRecord ( $ record ) ; } } return $ imported ; } | Import records . |
49,726 | private function getRecordsByHandle ( array $ records ) : array { $ recordsByHandle = [ ] ; foreach ( $ records as $ record ) { $ modelClass = get_class ( $ record ) ; $ converter = Craft :: $ app -> controller -> module -> getConverter ( $ modelClass ) ; $ index = $ converter -> getRecordIndex ( $ record ) ; $ recordsByHandle [ $ index ] = $ record ; } return $ recordsByHandle ; } | Get records by handle . |
49,727 | private function findOrNewRecord ( array $ recordsByHandle , array $ definition , string $ handle ) : Model { $ record = new $ definition [ 'class' ] ( ) ; if ( array_key_exists ( $ handle , $ recordsByHandle ) ) { $ existing = $ recordsByHandle [ $ handle ] ; if ( get_class ( $ record ) == get_class ( $ existing ) ) { $ record = $ existing ; } else { $ record -> id = $ existing -> id ; $ record -> setAttributes ( $ existing -> getAttributes ( ) ) ; } } return $ record ; } | Find record from records by handle or new record . |
49,728 | public function afterImport ( ) { $ obj = Craft :: $ app -> globals ; $ refObject = new \ ReflectionObject ( $ obj ) ; if ( $ refObject -> hasProperty ( '_allGlobalSets' ) ) { $ refProperty1 = $ refObject -> getProperty ( '_allGlobalSets' ) ; $ refProperty1 -> setAccessible ( true ) ; $ refProperty1 -> setValue ( $ obj , null ) ; } } | Reset craft global sets cache using reflection . |
49,729 | private function resetCraftSitesServiceGroupsCache ( ) { $ obj = Craft :: $ app -> sites ; $ refObject = new \ ReflectionObject ( $ obj ) ; if ( $ refObject -> hasProperty ( '_fetchedAllGroups' ) ) { $ refProperty = $ refObject -> getProperty ( '_fetchedAllGroups' ) ; $ refProperty -> setAccessible ( true ) ; $ refProperty -> setValue ( $ obj , false ) ; } } | Reset craft site service groups cache using reflection . |
49,730 | private function resetCraftFieldsServiceGroupsCache ( ) { $ obj = Craft :: $ app -> fields ; $ refObject = new \ ReflectionObject ( $ obj ) ; if ( $ refObject -> hasProperty ( '_fetchedAllGroups' ) ) { $ refProperty = $ refObject -> getProperty ( '_fetchedAllGroups' ) ; $ refProperty -> setAccessible ( true ) ; $ refProperty -> setValue ( $ obj , false ) ; } } | Reset craft fields service groups cache using reflection . |
49,731 | public function getFieldLayoutDefinition ( FieldLayout $ fieldLayout ) : array { if ( $ fieldLayout -> getTabs ( ) ) { $ tabDefinitions = [ ] ; foreach ( $ fieldLayout -> getTabs ( ) as $ tab ) { $ tabDefinitions [ $ tab -> name ] = $ this -> getFieldLayoutFieldsDefinition ( $ tab -> getFields ( ) ) ; } return [ 'type' => $ fieldLayout -> type , 'tabs' => $ tabDefinitions ] ; } return [ 'type' => $ fieldLayout -> type , 'fields' => $ this -> getFieldLayoutFieldsDefinition ( $ fieldLayout -> getFields ( ) ) , ] ; } | Get field layout definition . |
49,732 | private function getFieldLayoutFieldsDefinition ( array $ fields ) : array { $ fieldDefinitions = [ ] ; foreach ( $ fields as $ field ) { $ fieldDefinitions [ $ field -> handle ] = $ field -> required ; } return $ fieldDefinitions ; } | Get field layout fields definition . |
49,733 | public function getFieldLayout ( array $ fieldLayoutDef ) : FieldLayout { $ layoutFields = [ ] ; $ requiredFields = [ ] ; if ( array_key_exists ( 'tabs' , $ fieldLayoutDef ) ) { foreach ( $ fieldLayoutDef [ 'tabs' ] as $ tabName => $ tabDef ) { $ layoutTabFields = $ this -> getPrepareFieldLayout ( $ tabDef ) ; $ requiredFields = array_merge ( $ requiredFields , $ layoutTabFields [ 'required' ] ) ; $ layoutFields [ $ tabName ] = $ layoutTabFields [ 'fields' ] ; } } elseif ( array_key_exists ( 'fields' , $ fieldLayoutDef ) ) { $ layoutTabFields = $ this -> getPrepareFieldLayout ( $ fieldLayoutDef ) ; $ requiredFields = $ layoutTabFields [ 'required' ] ; $ layoutFields = $ layoutTabFields [ 'fields' ] ; } $ fieldLayout = Craft :: $ app -> fields -> assembleLayout ( $ layoutFields , $ requiredFields ) ; if ( array_key_exists ( 'type' , $ fieldLayoutDef ) ) { $ fieldLayout -> type = $ fieldLayoutDef [ 'type' ] ; } else { $ fieldLayout -> type = Entry :: class ; } return $ fieldLayout ; } | Attempt to import a field layout . |
49,734 | private function getPrepareFieldLayout ( array $ fieldLayoutDef ) : array { $ layoutFields = [ ] ; $ requiredFields = [ ] ; foreach ( $ fieldLayoutDef as $ fieldHandle => $ required ) { $ field = Craft :: $ app -> fields -> getFieldByHandle ( $ fieldHandle ) ; if ( $ field instanceof Field ) { $ layoutFields [ ] = $ field -> id ; if ( $ required ) { $ requiredFields [ ] = $ field -> id ; } } } return [ 'fields' => $ layoutFields , 'required' => $ requiredFields , ] ; } | Get a prepared fieldLayout for the craft assembleLayout function . |
49,735 | private function clearEmptyGroups ( ) { foreach ( Craft :: $ app -> fields -> getAllGroups ( ) as $ group ) { if ( count ( $ group -> getFields ( ) ) == 0 ) { Craft :: $ app -> fields -> deleteGroup ( $ group ) ; } } } | Clear empty field groups |
49,736 | public function init ( ) { Craft :: setAlias ( '@NerdsAndCompany/Schematic' , __DIR__ ) ; $ config = [ 'components' => [ 'elementIndexMapper' => [ 'class' => ElementIndexMapper :: class , ] , 'emailSettingsMapper' => [ 'class' => EmailSettingsMapper :: class , ] , 'generalSettingsMapper' => [ 'class' => GeneralSettingsMapper :: class , ] , 'modelMapper' => [ 'class' => ModelMapper :: class , ] , 'pluginMapper' => [ 'class' => PluginMapper :: class , ] , 'userSettingsMapper' => [ 'class' => UserSettingsMapper :: class , ] , ] , 'dataTypes' => [ 'plugins' => PluginDataType :: class , 'sites' => SiteDataType :: class , 'volumes' => VolumeDataType :: class , 'assetTransforms' => AssetTransformDataType :: class , 'emailSettings' => EmailSettingsDataType :: class , 'fields' => FieldDataType :: class , 'generalSettings' => GeneralSettingsDataType :: class , 'sections' => SectionDataType :: class , 'globalSets' => GlobalSetDataType :: class , 'categoryGroups' => CategoryGroupDataType :: class , 'tagGroups' => TagGroupDataType :: class , 'userGroups' => UserGroupDataType :: class , 'userSettings' => UserSettingsDataType :: class , 'elementIndexSettings' => ElementIndexDataType :: class , ] , ] ; Craft :: configure ( $ this , $ config ) ; parent :: init ( ) ; } | Initialize the module . |
49,737 | public function getDataType ( string $ dataTypeHandle ) { if ( ! isset ( $ this -> dataTypes [ $ dataTypeHandle ] ) ) { Schematic :: error ( 'DataType ' . $ dataTypeHandle . ' is not registered' ) ; return null ; } $ dataTypeClass = $ this -> dataTypes [ $ dataTypeHandle ] ; if ( ! class_exists ( $ dataTypeClass ) ) { Schematic :: error ( 'Class ' . $ dataTypeClass . ' does not exist' ) ; return null ; } $ dataType = new $ dataTypeClass ( ) ; if ( ! $ dataType instanceof DataTypeInterface ) { Schematic :: error ( $ dataTypeClass . ' does not implement DataTypeInterface' ) ; return null ; } return $ dataType ; } | Get datatype by handle . |
49,738 | public function checkMapper ( string $ mapper ) : bool { if ( ! isset ( $ this -> $ mapper ) ) { Schematic :: error ( 'Mapper ' . $ mapper . ' not found' ) ; return false ; } if ( ! $ this -> $ mapper instanceof MapperInterface ) { Schematic :: error ( get_class ( $ this -> $ mapper ) . ' does not implement MapperInterface' ) ; return false ; } return true ; } | Check mapper handle is valid . |
49,739 | public function getConverter ( string $ modelClass , string $ originalClass = '' ) { if ( '' === $ originalClass ) { $ originalClass = $ modelClass ; } $ converterClass = 'NerdsAndCompany\\Schematic\\Converters\\' . ucfirst ( str_replace ( 'craft\\' , '' , $ modelClass ) ) ; $ event = new ConverterEvent ( [ 'modelClass' => $ modelClass , 'converterClass' => $ converterClass , ] ) ; $ this -> trigger ( self :: EVENT_RESOLVE_CONVERTER , $ event ) ; $ converterClass = $ event -> converterClass ; if ( class_exists ( $ converterClass ) ) { $ converter = new $ converterClass ( ) ; if ( $ converter instanceof ConverterInterface ) { return $ converter ; } } $ parentClass = get_parent_class ( $ modelClass ) ; if ( ! $ parentClass ) { Schematic :: error ( 'No converter found for ' . $ originalClass ) ; return null ; } return $ this -> getConverter ( $ parentClass , $ originalClass ) ; } | Find converter for model class . |
49,740 | public static function warning ( $ message ) { Craft :: $ app -> controller -> stdout ( $ message . PHP_EOL , Console :: FG_YELLOW ) ; } | Logs a warning message . |
49,741 | public static function importError ( Model $ record , string $ handle ) { static :: warning ( '- Error importing ' . get_class ( $ record ) . ' ' . $ handle ) ; $ errors = $ record -> getErrors ( ) ; if ( ! is_array ( $ errors ) ) { static :: error ( ' - An unknown error has occurred' ) ; return ; } foreach ( $ errors as $ subErrors ) { foreach ( $ subErrors as $ error ) { static :: error ( ' - ' . $ error ) ; } } } | Log an import error . |
49,742 | public function actionIndex ( ) : int { $ this -> disableLogging ( ) ; $ configurations = [ ] ; foreach ( $ this -> getDataTypes ( ) as $ dataTypeHandle ) { $ dataType = $ this -> module -> getDataType ( $ dataTypeHandle ) ; if ( null == $ dataType ) { continue ; } $ mapper = $ dataType -> getMapperHandle ( ) ; if ( ! $ this -> module -> checkMapper ( $ mapper ) ) { continue ; } $ records = $ dataType -> getRecords ( ) ; $ configurations [ $ dataTypeHandle ] = $ this -> module -> $ mapper -> export ( $ records ) ; } $ overrideData = [ ] ; if ( file_exists ( $ this -> overrideFile ) ) { $ overrideData = Data :: parseYamlFile ( $ this -> overrideFile ) ; } if ( $ this -> getStorageType ( ) === self :: SINGLE_FILE ) { $ this -> exportToSingle ( $ configurations , $ overrideData ) ; } if ( $ this -> getStorageType ( ) === self :: MULTIPLE_FILES ) { $ this -> exportToMultiple ( $ configurations , $ overrideData ) ; } return 0 ; } | Exports the Craft datamodel . |
49,743 | private function exportToSingle ( array $ configurations , array $ overrideData ) { $ configurations = array_replace_recursive ( $ configurations , $ overrideData ) ; FileHelper :: writeToFile ( $ this -> file , Data :: toYaml ( $ configurations ) ) ; Schematic :: info ( 'Exported schema to ' . $ this -> file ) ; } | Export schema to single file |
49,744 | private function exportToMultiple ( array $ configurations , array $ overrideData ) { if ( ! file_exists ( $ this -> path ) ) { mkdir ( $ this -> path , 2775 , true ) ; } foreach ( $ configurations as $ dataTypeHandle => $ configuration ) { Schematic :: info ( 'Exporting ' . $ dataTypeHandle ) ; foreach ( $ configuration as $ recordName => $ records ) { if ( isset ( $ overrideData [ $ dataTypeHandle ] [ $ recordName ] ) ) { $ records = array_replace_recursive ( $ records , $ overrideData [ $ dataTypeHandle ] [ $ recordName ] ) ; } $ fileName = $ this -> toSafeFileName ( $ dataTypeHandle . '.' . $ recordName . '.yml' ) ; FileHelper :: writeToFile ( $ this -> path . $ fileName , Data :: toYaml ( $ records ) ) ; Schematic :: info ( 'Exported ' . $ recordName . ' to ' . $ fileName ) ; } } } | Export schema to multiple files |
49,745 | public function create ( array $ paths ) { $ standards = new Standards ( ) ; foreach ( $ paths as $ path ) { $ standards -> addStandard ( $ this -> standardFactory -> create ( $ path ) ) ; } return $ standards ; } | Creates PHPCodeSniffer standards from paths . |
49,746 | public function compiler ( ) { static $ engineResolver ; if ( ! $ engineResolver ) { $ engineResolver = $ this -> getContainer ( ) -> make ( 'view.engine.resolver' ) ; } return $ engineResolver -> resolve ( 'blade' ) -> getCompiler ( ) ; } | Get the compiler |
49,747 | public function applyNamespaceToPath ( $ path ) { $ finder = $ this -> getContainer ( ) [ 'view.finder' ] ; if ( ! method_exists ( $ finder , 'getHints' ) ) { return $ path ; } $ delimiter = $ finder :: HINT_PATH_DELIMITER ; $ hints = $ finder -> getHints ( ) ; $ view = array_reduce ( array_keys ( $ hints ) , function ( $ view , $ namespace ) use ( $ delimiter , $ hints ) { return str_replace ( $ hints [ $ namespace ] , $ namespace . $ delimiter , $ view ) ; } , $ path ) ; return preg_replace ( "%{$delimiter}[\\/]*%" , $ delimiter , $ view ) ; } | Convert path to view namespace |
49,748 | public function removeStandard ( $ standard ) { if ( $ this -> hasStandard ( $ standard ) ) { unset ( $ this -> standards [ $ this -> getStandardName ( $ standard ) ] ) ; } return $ this ; } | Remove a single standard from the set . |
49,749 | public function getStandard ( $ standard ) { if ( ! $ this -> hasStandard ( $ standard ) ) { return null ; } return $ this -> standards [ $ this -> getStandardName ( $ standard ) ] ; } | Get a single standard . |
49,750 | public function setStandards ( array $ standards ) { $ this -> standards = [ ] ; foreach ( $ standards as $ standard ) { $ this -> addStandard ( $ standard ) ; } return $ this ; } | Set standards hold by this set . |
49,751 | private function escapeArgs ( & $ args ) { $ escaped = array ( ) ; foreach ( $ args as $ arg ) { $ escaped [ ] = escapeshellarg ( $ arg ) ; } return $ escaped ; } | Escape given argument array |
49,752 | protected function readStream ( & $ stream , & $ output ) { $ content = stream_get_contents ( $ stream ) ; if ( strlen ( rtrim ( $ content ) ) ) { foreach ( preg_split ( '/\r?\n/' , $ content ) as $ line ) { $ output [ ] = $ line ; } } } | Read stream content to output array |
49,753 | protected function faststart ( $ src ) { if ( ! $ this -> config [ 'qt-faststart.bin' ] ) { return 0 ; } $ output = array ( ) ; $ dst = $ src . '.mp4' ; $ result = $ this -> Process -> run ( $ this -> config [ 'qt-faststart.bin' ] , array ( $ src , $ dst ) , $ output ) ; if ( $ result == 0 ) { unlink ( $ src ) ; rename ( $ dst , $ src ) ; } return $ result ; } | Move mp4 meta data to the front to support streaming |
49,754 | public function in ( $ path ) { $ finder = $ this -> getSymfonyFinder ( ) -> in ( $ path ) -> files ( ) -> name ( 'ruleset.xml' ) -> sortByName ( ) ; $ paths = iterator_to_array ( $ finder , false ) ; $ paths = array_map ( function ( \ SplFileInfo $ file ) { return $ file -> getPath ( ) ; } , $ paths ) ; return $ this -> createStandardsFromPaths ( $ paths ) ; } | Find and return PHPCodeSniffer standards . |
49,755 | protected function parseEncoder ( $ lines ) { $ encoders = array ( ) ; foreach ( $ lines as $ line ) { if ( preg_match ( '/^\s+([A-Z .]+)\s+(\w{2,})\s+(.*)$/' , $ line , $ m ) ) { $ type = trim ( $ m [ 1 ] ) ; if ( strpos ( $ type , 'E' ) !== false ) { $ encoder = trim ( $ m [ 2 ] ) ; if ( strpos ( $ encoder , ',' ) !== false ) { foreach ( split ( ',' , $ encoder ) as $ e ) { $ encoders [ ] = $ e ; } } else { $ encoders [ ] = $ encoder ; } } } } sort ( $ encoders ) ; return $ encoders ; } | Extract encoder names from output lines |
49,756 | protected function parseInfo ( $ lines ) { $ result = array ( 'videoStreams' => 0 , 'audioStreams' => 0 ) ; foreach ( $ lines as $ line ) { if ( preg_match ( '/Duration:\s+(\d\d):(\d\d):(\d\d\.\d+)/' , $ line , $ m ) ) { $ result [ 'duration' ] = $ m [ 1 ] * 3600 + $ m [ 2 ] * 60 + $ m [ 3 ] ; } else if ( preg_match ( '/\s+Stream #(\d)+.*$/' , $ line , $ sm ) ) { if ( strpos ( $ line , 'Video:' ) ) { $ result [ 'videoStreams' ] ++ ; $ words = preg_split ( '/,?\s+/' , trim ( $ line ) ) ; for ( $ i = 0 ; $ i < count ( $ words ) ; $ i ++ ) { if ( preg_match ( '/(\d+)x(\d+)/' , $ words [ $ i ] , $ m ) ) { $ result [ 'width' ] = $ m [ 1 ] ; $ result [ 'height' ] = $ m [ 2 ] ; } } } else if ( strpos ( $ line , 'Audio:' ) ) { $ result [ 'audioStreams' ] ++ ; } } } return $ result ; } | Parse streaming informations |
49,757 | protected function isVersionIsGreaterOrEqual ( $ version , $ other ) { $ max = min ( count ( $ version ) , count ( $ other ) ) ; for ( $ i = 0 ; $ i < $ max ; $ i ++ ) { if ( $ version [ $ i ] < $ other [ $ i ] ) { return false ; } } return true ; } | Compare two versions |
49,758 | protected function searchEncoder ( $ needle ) { if ( is_array ( $ needle ) ) { foreach ( $ needle as $ n ) { $ result = $ this -> searchEncoder ( $ n ) ; if ( $ result ) { return $ result ; } } return false ; } $ encoders = $ this -> getEncoders ( ) ; foreach ( $ encoders as $ encoder ) { if ( strpos ( $ encoder , $ needle ) !== false ) { return $ encoder ; } } return false ; } | Search for matching encoder |
49,759 | protected function getDriver ( ) { $ version = $ this -> getVersion ( ) ; if ( $ this -> isVersionIsGreaterOrEqual ( $ version , array ( 0 , 11 , 0 ) ) ) { return new Driver \ FfmpegDriver ( ) ; } else if ( $ this -> isVersionIsGreaterOrEqual ( $ version , array ( 0 , 9 , 0 ) ) ) { return new Driver \ FfmpegDriver10 ( ) ; } else if ( $ this -> isVersionIsGreaterOrEqual ( $ version , array ( 0 , 8 , 0 ) ) ) { return new Driver \ FfmpegDriver08 ( ) ; } else { return new Driver \ FfmpegDriver06 ( ) ; } } | Get current ffmpeg driver |
49,760 | protected function createConverter ( $ targetFormat , $ profileName ) { $ profile = $ this -> getProfile ( $ profileName ) ; $ videoContainers = $ this -> config [ 'videoContainers' ] ; if ( ! isset ( $ videoContainers [ $ targetFormat ] ) ) { throw new \ Exception ( "Unsupported target video container" ) ; } $ targetConfig = $ videoContainers [ $ targetFormat ] ; if ( ! isset ( $ targetConfig [ 'videoEncoder' ] ) || ! isset ( $ targetConfig [ 'audioEncoder' ] ) ) { throw new \ Exception ( "Video or audio encoder are missing for target format $targetFormat" ) ; } $ videoEncoder = $ this -> searchEncoder ( $ targetConfig [ 'videoEncoder' ] ) ; if ( ! $ videoEncoder ) { throw new \ Exception ( "Video encoder not found for video codec {$targetConfig['videoEncoder']} for $targetFormat" ) ; } $ audioEncoder = $ this -> searchEncoder ( $ targetConfig [ 'audioEncoder' ] ) ; if ( ! $ audioEncoder ) { throw new \ Exception ( "Audio encoder not found for audio codec {$targetConfig['audioEncoder']} for $targetFormat" ) ; } if ( $ targetFormat == 'mp4' ) { return new Converter \ Mp4Converter ( $ this -> Process , $ this -> getDriver ( ) , $ this -> config , $ profile , $ videoEncoder , $ audioEncoder ) ; } return new Converter \ GenericConverter ( $ this -> Process , $ this -> getDriver ( ) , $ this -> config , $ profile , $ videoEncoder , $ audioEncoder ) ; } | Create a video convert for given profile and target container |
49,761 | protected function mergeOptions ( $ src , $ dst , & $ options ) { if ( ! isset ( $ options [ 'width' ] ) && ! isset ( $ options [ 'height' ] ) ) { $ info = $ this -> getVideoInfo ( $ src ) ; $ options [ 'width' ] = $ info [ 'width' ] ; $ options [ 'height' ] = $ info [ 'height' ] ; if ( ! $ info [ 'audioStreams' ] ) { $ options [ 'audio' ] = false ; } } if ( ! isset ( $ options [ 'targetFormat' ] ) ) { $ ext = strtolower ( substr ( $ dst , strrpos ( $ dst , '.' ) + 1 ) ) ; $ options [ 'targetFormat' ] = $ ext ; } } | If no width and height are given in the option read the video file and set width and height from the souce |
49,762 | public function getVersion ( ) { $ version = $ this -> Cache -> read ( 'version' , null ) ; if ( $ version !== null ) { return $ version ; } $ version = array ( 2 , 0 , 0 ) ; $ lines = array ( ) ; $ result = $ this -> Process -> run ( $ this -> config [ 'ffmpeg.bin' ] , array ( '-version' ) , $ lines ) ; if ( $ result == 0 && $ lines && preg_match ( '/^\w+\s(version\s)?(\d+)\.(\d+)\.(\d+).*/' , $ lines [ 0 ] , $ m ) ) { $ version = array ( $ m [ 2 ] , $ m [ 3 ] , $ m [ 4 ] ) ; } else if ( $ result == 0 && $ lines && preg_match ( '/^\w+\s(version\s)?\S*N-(\d+)-.*/' , $ lines [ 0 ] , $ m ) ) { $ winVersion = $ m [ 2 ] ; if ( $ winVersion <= 30610 ) { $ version = array ( 0 , 6 , 0 ) ; } else if ( $ winVersion <= 30956 ) { $ version = array ( 0 , 7 , 0 ) ; } else if ( $ winVersion <= 48409 ) { $ version = array ( 0 , 8 , 0 ) ; } else if ( $ winVersion <= 48610 ) { $ version = array ( 1 , 0 , 1 ) ; } else if ( $ winVersion <= 49044 ) { $ version = array ( 1 , 1 , 0 ) ; } else { $ version = array ( 2 , 0 , 0 ) ; } } $ this -> Cache -> write ( 'version' , $ version ) ; return $ version ; } | Get current version of ffmpeg |
49,763 | public function getEncoders ( ) { $ encoders = $ this -> Cache -> read ( 'encoders' ) ; if ( $ encoders !== null ) { return $ encoders ; } $ args = array ( '-codecs' ) ; if ( ! $ this -> isVersionIsGreaterOrEqual ( $ this -> getVersion ( ) , array ( 0 , 8 ) ) ) { $ args = array ( '-formats' ) ; } $ lines = array ( ) ; $ errCode = $ this -> Process -> run ( $ this -> config [ 'ffmpeg.bin' ] , $ args , $ lines ) ; if ( ! count ( $ lines ) || $ errCode != 0 ) { return array ( ) ; } $ encoders = $ this -> parseEncoder ( $ lines ) ; $ this -> Cache -> write ( 'encoders' , $ encoders ) ; return $ encoders ; } | Get supported encoder names |
49,764 | public function getProfile ( $ name ) { $ dirs = $ this -> config [ 'profile.dirs' ] ; foreach ( $ dirs as $ dir ) { if ( ! is_dir ( $ dir ) || ! is_readable ( $ dir ) ) { continue ; } $ filename = $ dir . DIRECTORY_SEPARATOR . $ name . '.profile' ; if ( is_readable ( $ filename ) ) { $ content = file_get_contents ( $ filename ) ; $ json = json_decode ( $ content ) ; return $ json ; } } throw new \ Exception ( "Profile $name not found" ) ; } | Read the video profile in given profile directories |
49,765 | public function listProfiles ( ) { $ dirs = $ this -> config [ 'profile.dirs' ] ; $ profiles = array ( ) ; foreach ( $ dirs as $ dir ) { if ( ! is_dir ( $ dir ) || ! is_readable ( $ dir ) ) { continue ; } $ files = scandir ( $ dir ) ; foreach ( $ files as $ file ) { if ( preg_match ( '/(.*)\.profile$/' , $ file , $ m ) ) { $ profiles [ ] = $ m [ 1 ] ; } } } return $ profiles ; } | List all available profiles |
49,766 | public function getVideoInfo ( $ src ) { $ lines = array ( ) ; if ( ! is_readable ( $ src ) ) { throw new \ Exception ( "Source file '$src' is not readable" ) ; } $ this -> Process -> run ( $ this -> config [ 'ffmpeg.bin' ] , array ( '-i' , $ src ) , $ lines ) ; if ( count ( $ lines ) ) { return $ this -> parseInfo ( $ lines ) ; } return false ; } | Get information about a video file |
49,767 | public function convert ( $ src , $ dst , $ profileName , $ options = array ( ) ) { $ this -> setTimeLimit ( ) ; $ this -> mergeOptions ( $ src , $ dst , $ options ) ; $ converter = $ this -> createConverter ( $ options [ 'targetFormat' ] , $ profileName ) ; $ result = $ converter -> create ( $ src , $ dst , $ options ) ; return $ result ; } | Convert a given video to html5 video |
49,768 | public function getPossibleViewFiles ( $ name ) { $ parts = explode ( self :: FALLBACK_PARTS_DELIMITER , $ name ) ; $ templates [ ] = array_shift ( $ parts ) ; foreach ( $ parts as $ i => $ part ) { $ templates [ ] = $ templates [ $ i ] . self :: FALLBACK_PARTS_DELIMITER . $ part ; } rsort ( $ templates ) ; return $ this -> getPossibleViewFilesFromTemplates ( $ templates ) ; } | Get an array of possible view files from a single file name . |
49,769 | public function getPossibleViewFilesFromTemplates ( $ templates ) { return call_user_func_array ( 'array_merge' , array_map ( function ( $ template ) { return array_map ( function ( $ extension ) use ( $ template ) { return str_replace ( '.' , '/' , $ template ) . '.' . $ extension ; } , $ this -> extensions ) ; } , $ templates ) ) ; } | Get an array of possible view files from an array of templates |
49,770 | protected function getNameFromRuleSet ( $ ruleSetXmlPath ) { try { $ ruleSet = new \ SimpleXMLElement ( file_get_contents ( $ ruleSetXmlPath ) ) ; $ name = trim ( $ ruleSet -> attributes ( ) [ 'name' ] ) ; if ( $ name !== '' ) { return $ name ; } } catch ( \ Exception $ e ) { } return basename ( dirname ( $ ruleSetXmlPath ) ) ; } | Fetch PHPCodeSniffer standard name from ruleset . xml . |
49,771 | public function categoriesAdd ( Request $ request , Response $ response ) { if ( $ check = $ this -> sentinel -> hasPerm ( 'blog_categories.create' , 'dashboard' , $ this -> config [ 'blog-enabled' ] ) ) { return $ check ; } if ( $ request -> isPost ( ) ) { $ this -> validator -> validate ( $ request , [ 'category_name' => V :: length ( 2 , 25 ) -> alpha ( '\'' ) , 'category_slug' => V :: slug ( ) ] ) ; $ checkSlug = BC :: where ( 'slug' , '=' , $ request -> getParam ( 'category_slug' ) ) -> get ( ) -> count ( ) ; if ( $ checkSlug > 0 ) { $ this -> validator -> addError ( 'category_slug' , 'Slug already in use.' ) ; } if ( $ this -> validator -> isValid ( ) ) { $ addCategory = new BC ; $ addCategory -> name = $ request -> getParam ( 'category_name' ) ; $ addCategory -> slug = $ request -> getParam ( 'category_slug' ) ; if ( $ addCategory -> save ( ) ) { $ this -> flash ( 'success' , 'Category added successfully.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } } $ this -> flash ( 'danger' , 'An error occured while adding this category.' ) ; } return $ this -> redirect ( $ response , 'admin-blog' ) ; } | Add New Blog Category |
49,772 | public function categoriesDelete ( Request $ request , Response $ response ) { if ( $ check = $ this -> sentinel -> hasPerm ( 'blog_categories.delete' , 'dashboard' , $ this -> config [ 'blog-enabled' ] ) ) { return $ check ; } $ category = BC :: find ( $ request -> getParam ( 'category_id' ) ) ; if ( ! $ category ) { $ this -> flash ( 'danger' , 'Category doesn\'t exist.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } if ( $ category -> delete ( ) ) { $ this -> flash ( 'success' , 'Category has been removed.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } $ this -> flash ( 'danger' , 'There was a problem removing the category.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } | Delete Blog Category |
49,773 | public function categoriesEdit ( Request $ request , Response $ response , $ categoryId ) { if ( $ check = $ this -> sentinel -> hasPerm ( 'blog_categories.update' , 'dashboard' , $ this -> config [ 'blog-enabled' ] ) ) { return $ check ; } $ category = BC :: find ( $ categoryId ) ; if ( ! $ category ) { $ this -> flash ( 'danger' , 'Sorry, that category was not found.' ) ; return $ response -> withRedirect ( $ this -> router -> pathFor ( 'admin-blog' ) ) ; } if ( $ request -> isPost ( ) ) { $ categoryName = $ request -> getParam ( 'category_name' ) ; $ categorySlug = $ request -> getParam ( 'category_slug' ) ; $ validateData = array ( 'category_name' => array ( 'rules' => V :: length ( 2 , 25 ) -> alpha ( '\'' ) , 'messages' => array ( 'length' => 'Must be between 2 and 25 characters.' , 'alpha' => 'Letters only and can contain \'' ) ) , 'category_slug' => array ( 'rules' => V :: slug ( ) , 'messages' => array ( 'slug' => 'May only contain lowercase letters, numbers and hyphens.' ) ) ) ; $ this -> validator -> validate ( $ request , $ validateData ) ; $ checkSlug = $ category -> where ( 'id' , '!=' , $ category -> id ) -> where ( 'slug' , '=' , $ categorySlug ) -> get ( ) -> count ( ) ; if ( $ checkSlug > 0 && $ categorySlug != $ category -> slug ) { $ this -> validator -> addError ( 'category_slug' , 'Category slug is already in use.' ) ; } if ( $ this -> validator -> isValid ( ) ) { if ( $ category -> id == 1 ) { $ this -> flash ( 'danger' , 'Cannot edit uncategorized category.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } $ category -> name = $ categoryName ; $ category -> slug = $ categorySlug ; if ( $ category -> save ( ) ) { $ this -> flash ( 'success' , 'Category has been updated successfully.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } } $ this -> flash ( 'danger' , 'An error occured updating the category.' ) ; } return $ this -> view -> render ( $ response , 'blog-categories-edit.twig' , [ 'category' => $ category ] ) ; } | Edit Blog Category |
49,774 | public function ReadUserSpace ( $ frompos = 1 , $ readlen = 0 , $ receiveStructure = null ) { $ dataRead = ' ' ; $ params [ ] = Toolkit :: AddParameterChar ( 'in' , 20 , "User space name and library" , 'userspacename' , $ this -> getUSFullName ( ) ) ; $ params [ ] = Toolkit :: AddParameterInt32 ( 'in' , "From position" , 'position_from' , $ frompos ) ; $ receiverVarName = 'receiverdata' ; if ( $ receiveStructure ) { if ( ! is_object ( $ receiveStructure ) ) { throw new \ Exception ( 'Parameter 3 passed to ReadUserSpace must be a ProgramParameter object.' ) ; } $ labelForSizeOfInputData = 'dssize' ; $ params [ ] = Toolkit :: AddParameterSize ( "Length of data" , 'dataLen' , $ labelForSizeOfInputData ) ; $ receiveDs [ ] = $ receiveStructure ; $ params [ ] = Toolkit :: AddDataStruct ( $ receiveDs , $ receiverVarName , 0 , '' , false , $ labelForSizeOfInputData ) ; } else { $ params [ ] = Toolkit :: AddParameterInt32 ( 'in' , "Size of data" , 'datasize' , $ readlen ) ; $ params [ ] = Toolkit :: AddParameterChar ( 'out' , $ readlen , $ receiverVarName , $ receiverVarName , $ receiveStructure ) ; } $ params [ ] = Toolkit :: AddErrorDataStruct ( ) ; $ retPgmArr = $ this -> ToolkitSrvObj -> PgmCall ( 'QUSRTVUS' , 'QSYS' , $ params ) ; if ( $ this -> ToolkitSrvObj -> verify_CPFError ( $ retPgmArr , "Read user space failed. Error:" ) ) return false ; $ retArr = $ retPgmArr [ 'io_param' ] ; return $ retArr [ $ receiverVarName ] ; } | if receiveDescription given readlen = 0 |
49,775 | public function getUSFullName ( ) { if ( $ this -> USName != null ) { return sprintf ( "%-10s%-10s" , $ this -> USName , $ this -> USlib ) ; } return NULL ; } | Name and Library |
49,776 | public function blog ( Request $ request , Response $ response ) { $ page = 1 ; $ routeArgs = $ request -> getAttribute ( 'route' ) -> getArguments ( ) ; if ( isset ( $ routeArgs [ 'page' ] ) && is_numeric ( $ routeArgs [ 'page' ] ) ) { $ page = $ routeArgs [ 'page' ] ; } $ posts = BlogPosts :: where ( 'status' , 1 ) -> where ( 'publish_at' , '<' , Carbon :: now ( ) ) -> with ( 'category' , 'tags' , 'author' ) -> withCount ( 'comments' , 'pendingComments' ) -> orderBy ( 'publish_at' , 'DESC' ) ; $ pagination = new Paginator ( $ posts -> count ( ) , $ this -> config [ 'blog-per-page' ] , $ page , "/blog/(:num)" ) ; $ pagination = $ pagination ; $ posts = $ posts -> skip ( $ this -> config [ 'blog-per-page' ] * ( $ page - 1 ) ) -> take ( $ this -> config [ 'blog-per-page' ] ) ; return $ this -> view -> render ( $ response , 'blog.twig' , array ( "posts" => $ posts -> get ( ) , "pagination" => $ pagination ) ) ; } | Main Blog Page |
49,777 | public function blogAuthor ( Request $ request , Response $ response ) { $ routeArgs = $ request -> getAttribute ( 'route' ) -> getArguments ( ) ; $ checkAuthor = Users :: where ( 'username' , $ routeArgs [ 'username' ] ) -> first ( ) ; if ( ! $ checkAuthor ) { $ this -> flash ( 'warning' , 'Author not found.' ) ; return $ this -> redirect ( $ response , 'blog' ) ; } $ page = 1 ; if ( isset ( $ routeArgs [ 'page' ] ) && is_numeric ( $ routeArgs [ 'page' ] ) ) { $ page = $ routeArgs [ 'page' ] ; } $ posts = BlogPosts :: where ( 'status' , 1 ) -> where ( 'user_id' , $ checkAuthor -> id ) -> where ( 'publish_at' , '<' , Carbon :: now ( ) ) -> with ( 'category' , 'tags' , 'author' ) -> withCount ( 'comments' , 'pendingComments' ) -> orderBy ( 'publish_at' , 'DESC' ) ; $ pagination = new Paginator ( $ posts -> count ( ) , $ this -> config [ 'blog-per-page' ] , $ page , "/blog/author/" . $ checkAuthor -> username . "/(:num)" ) ; $ pagination = $ pagination ; $ posts = $ posts -> skip ( $ this -> config [ 'blog-per-page' ] * ( $ page - 1 ) ) -> take ( $ this -> config [ 'blog-per-page' ] ) ; return $ this -> view -> render ( $ response , 'blog.twig' , array ( "author" => $ checkAuthor , "posts" => $ posts -> get ( ) , "pagination" => $ pagination , "authorPage" => true ) ) ; } | Author Posts Page |
49,778 | public function blogCategory ( Request $ request , Response $ response ) { $ routeArgs = $ request -> getAttribute ( 'route' ) -> getArguments ( ) ; $ checkCat = BlogCategories :: where ( 'slug' , $ routeArgs [ 'slug' ] ) -> first ( ) ; if ( ! $ checkCat ) { $ this -> flash ( 'warning' , 'Tag not found.' ) ; return $ this -> redirect ( $ response , 'blog' ) ; } $ page = 1 ; if ( isset ( $ routeArgs [ 'page' ] ) && is_numeric ( $ routeArgs [ 'page' ] ) ) { $ page = $ routeArgs [ 'page' ] ; } $ posts = BlogCategories :: withCount ( [ 'posts' => function ( $ query ) { $ query -> where ( 'status' , 1 ) -> where ( 'publish_at' , '<' , Carbon :: now ( ) ) ; } ] ) -> with ( [ 'posts' => function ( $ query ) use ( $ page ) { $ query -> where ( 'status' , 1 ) -> where ( 'publish_at' , '<' , Carbon :: now ( ) ) -> with ( 'category' , 'tags' , 'author' ) -> withCount ( 'comments' , 'pendingComments' ) -> skip ( $ this -> config [ 'blog-per-page' ] * ( $ page - 1 ) ) -> take ( $ this -> config [ 'blog-per-page' ] ) -> orderBy ( 'publish_at' , 'DESC' ) ; } ] ) -> find ( $ checkCat -> id ) ; $ pagination = new Paginator ( $ posts -> posts_count , $ this -> config [ 'blog-per-page' ] , $ page , "/blog/category/" . $ checkCat -> slug . "/(:num)" ) ; $ pagination = $ pagination ; return $ this -> view -> render ( $ response , 'blog.twig' , array ( "category" => $ checkCat , "posts" => $ posts -> posts , "pagination" => $ pagination , "categoryPage" => true ) ) ; } | Category Posts Page |
49,779 | protected function findValueInArray ( $ searchKey , $ valueArray ) { $ connection = $ this -> getConnection ( ) ; if ( ! count ( $ valueArray ) ) { i5ErrorActivity ( I5_ERR_PHP_TYPEPARAM , I5_CAT_PHP , "Array of input values must not be empty" , "Array of input values must not be empty" ) ; return false ; } foreach ( $ valueArray as $ key => $ value ) { if ( $ key == $ searchKey ) { return $ value ; } } return false ; } | Given an array key name recursively search the input values array and return the value associated with the key name provided . |
49,780 | public function callProgram ( $ newInputParams = array ( ) ) { $ pgmInfo = $ this -> getObjInfo ( ) ; $ pgmName = $ pgmInfo [ 'obj' ] ; $ lib = $ pgmInfo [ 'lib' ] ; $ func = $ pgmInfo [ 'func' ] ; $ options = array ( ) ; if ( $ func ) { $ options [ 'func' ] = $ func ; } $ pgmCallOutput = $ this -> getConnection ( ) -> PgmCall ( $ pgmName , $ lib , $ newInputParams , null , $ options ) ; $ conn = $ this -> getConnection ( ) ; if ( $ pgmCallOutput ) { $ outputParams = $ conn -> getOutputParam ( $ pgmCallOutput ) ; $ this -> setPgmOutput ( $ outputParams ) ; return true ; } else { return false ; } } | Given input values and an output array in a particular format and having captured the data description and program info in the constructor and having converted the data desc and interpolated the values Now we call the program and return an array of output variables . |
49,781 | protected function findInputValueByName ( $ name , $ inputArray ) { foreach ( $ inputArray as $ key => $ value ) { if ( $ key === $ name ) { return $ value ; } if ( is_array ( $ value ) ) { if ( ( $ result = $ this -> findInputValueByName ( $ name , $ value ) ) !== false ) { return $ result ; } } } return false ; } | search through entire input array for the value indicated by name . |
49,782 | public function tagsAdd ( Request $ request , Response $ response ) { if ( $ check = $ this -> sentinel -> hasPerm ( 'blog_tags.create' , 'dashboard' , $ this -> config [ 'blog-enabled' ] ) ) { return $ check ; } if ( $ request -> isPost ( ) ) { $ tagName = $ request -> getParam ( 'tag_name' ) ; $ tagSlug = $ request -> getParam ( 'tag_slug' ) ; $ this -> validator -> validate ( $ request , [ 'tag_name' => V :: length ( 2 , 25 ) -> alpha ( '\'' ) , 'tag_slug' => V :: slug ( ) ] ) ; $ checkSlug = BT :: where ( 'slug' , '=' , $ request -> getParam ( 'tag_slug' ) ) -> get ( ) -> count ( ) ; if ( $ checkSlug > 0 ) { $ this -> validator -> addError ( 'tag_slug' , 'Slug already in use.' ) ; } if ( $ this -> validator -> isValid ( ) ) { $ addTag = new BT ; $ addTag -> name = $ tagName ; $ addTag -> slug = $ tagSlug ; if ( $ addTag -> save ( ) ) { $ this -> flash ( 'success' , 'Category added successfully.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } } $ this -> flash ( 'danger' , 'There was a problem adding the tag.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } } | Add New Blog Tag |
49,783 | public function tagsDelete ( Request $ request , Response $ response ) { if ( $ check = $ this -> sentinel -> hasPerm ( 'blog_tags.delete' , 'dashboard' , $ this -> config [ 'blog-enabled' ] ) ) { return $ check ; } $ tag = BT :: find ( $ request -> getParam ( 'tag_id' ) ) ; if ( ! $ tag ) { $ this -> flash ( 'danger' , 'Tag doesn\'t exist.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } if ( $ tag -> delete ( ) ) { $ this -> flash ( 'success' , 'Tag has been removed.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } $ this -> flash ( 'danger' , 'There was a problem removing the tag.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } | Delete Blog Tag |
49,784 | public function tagsEdit ( Request $ request , Response $ response , $ tagId ) { if ( $ check = $ this -> sentinel -> hasPerm ( 'blog_tags.update' , 'dashboard' , $ this -> config [ 'blog-enabled' ] ) ) { return $ check ; } $ tag = BT :: find ( $ tagId ) ; if ( ! $ tag ) { $ this -> flash ( 'danger' , 'Tag doesn\'t exist.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } if ( $ request -> isPost ( ) ) { $ tagName = $ request -> getParam ( 'tag_name' ) ; $ tagSlug = $ request -> getParam ( 'tag_slug' ) ; $ validateData = array ( 'tag_name' => array ( 'rules' => V :: length ( 2 , 25 ) -> alpha ( '\'' ) , 'messages' => array ( 'length' => 'Must be between 2 and 25 characters.' , 'alpha' => 'Letters only and can contain \'' ) ) , 'tag_slug' => array ( 'rules' => V :: slug ( ) , 'messages' => array ( 'slug' => 'May only contain lowercase letters, numbers and hyphens.' ) ) ) ; $ this -> validator -> validate ( $ request , $ validateData ) ; $ checkSlug = $ tag -> where ( 'id' , '!=' , $ tagId ) -> where ( 'slug' , '=' , $ tagSlug ) -> get ( ) -> count ( ) ; if ( $ checkSlug > 0 && $ tagSlug != $ tag [ 'slug' ] ) { $ this -> validator -> addError ( 'tag_slug' , 'Category slug is already in use.' ) ; } if ( $ this -> validator -> isValid ( ) ) { $ tag -> name = $ tagName ; $ tag -> slug = $ tagSlug ; if ( $ tag -> save ( ) ) { $ this -> flash ( 'success' , 'Category has been updated successfully.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } $ this -> flash ( 'success' , 'An unknown error occured.' ) ; } } return $ this -> view -> render ( $ response , 'blog-tags-edit.twig' , [ 'tag' => $ tag ] ) ; } | Edit Blog Tag |
49,785 | protected function getDefaultServiceParams ( ) { return array ( 'XMLServiceLib' => $ this -> getConfigValue ( 'system' , 'XMLServiceLib' , 'ZENDSVR6' ) , 'HelperLib' => $ this -> getConfigValue ( 'system' , 'HelperLib' , 'ZENDSVR6' ) , 'debug' => $ this -> getConfigValue ( 'system' , 'debug' , false ) , 'debugLogFile' => $ this -> getConfigValue ( 'system' , 'debugLogFile' , false ) , 'encoding' => $ this -> getConfigValue ( 'system' , 'encoding' , 'ISO-8859-1' ) , 'parseOnly' => $ this -> getConfigValue ( 'testing' , 'parse_only' , false ) , 'parseDebugLevel' => $ this -> getConfigValue ( 'testing' , 'parse_debug_level' , null ) ) ; } | get service param values from Config to use in object |
49,786 | protected function getOptionalParams ( $ type , array $ optionalParams ) { foreach ( $ optionalParams as $ optionalParamName ) { $ val = $ this -> getConfigValue ( $ type , $ optionalParamName ) ; if ( $ val ) { $ this -> serviceParams [ $ optionalParamName ] = $ val ; } $ this -> optionalParamNames = $ optionalParamName ; } } | get optional param values from Config and add them to the service params |
49,787 | protected function plugSizeToBytes ( $ plugSize ) { if ( isset ( $ this -> _dataSize [ $ plugSize ] ) ) { return $ this -> _dataSize [ $ plugSize ] ; } throw new \ Exception ( "plugSize '$plugSize' is not valid. Try one of these: " . $ this -> validPlugSizeList ( ) ) ; } | return size in bytes based on plugSize . |
49,788 | protected function setDb ( $ transportType = '' ) { $ transportType = trim ( $ transportType ) ; $ extensionName = ( $ transportType ) ? $ transportType : DBPROTOCOL ; if ( ! extension_loaded ( $ extensionName ) ) { throw new \ Exception ( "Extension $extensionName not loaded." ) ; } if ( $ extensionName === 'ibm_db2' ) { $ this -> setOptions ( array ( 'plugPrefix' => 'iPLUG' ) ) ; $ this -> db = new db2supp ( ) ; $ this -> setDb2 ( ) ; } elseif ( $ extensionName === 'odbc' ) { $ this -> setOptions ( array ( 'plugPrefix' => 'iPLUGR' ) ) ; $ this -> db = new odbcsupp ( ) ; } $ this -> setTransport ( $ this -> db ) ; return ; } | transport type is same as db extension name when a db transport is used . |
49,789 | public function disconnectPersistent ( ) { $ this -> PgmCall ( "OFF" , NULL ) ; if ( isset ( $ this -> db ) && $ this -> db ) { $ this -> db -> disconnectPersistent ( $ this -> conn ) ; } $ this -> conn = null ; } | same as disconnect but also really close persistent database connection . |
49,790 | public function specialCall ( $ callType ) { $ this -> setOptions ( array ( $ callType => true ) ) ; $ outputArray = $ this -> PgmCall ( "NONE" , NULL , NULL , NULL ) ; $ this -> setOptions ( array ( $ callType => false ) ) ; return $ outputArray ; } | for special requests such as transport performance license |
49,791 | public function ExecuteProgram ( $ inputXml , $ disconnect = false ) { $ this -> execStartTime = '' ; $ this -> error = '' ; $ this -> VerifyPLUGName ( ) ; $ this -> VerifyInternalKey ( ) ; $ internalKey = $ this -> getInternalKey ( ) ; $ controlKeyString = $ this -> getControlKey ( $ disconnect ) ; $ plugSize = $ this -> getOption ( 'plugSize' ) ; if ( isset ( $ this -> db ) && $ this -> db ) { $ result = $ this -> makeDbCall ( $ internalKey , $ plugSize , $ controlKeyString , $ inputXml , $ disconnect ) ; } else { $ transport = $ this -> getTransport ( ) ; $ transport -> setIpc ( $ internalKey ) ; $ transport -> setCtl ( $ controlKeyString ) ; $ url = $ this -> getOption ( 'httpTransportUrl' ) ; $ transport -> setUrl ( $ url ) ; $ outByteSize = $ this -> plugSizeToBytes ( $ plugSize ) ; if ( $ this -> isDebug ( ) ) { $ this -> debugLog ( "\nExec start: " . date ( "Y-m-d H:i:s" ) . "\nVersion of toolkit front end: " . self :: getFrontEndVersion ( ) . "\nToolkit class: '" . __FILE__ . "'\nIPC: '" . $ this -> getInternalKey ( ) . "'. Control key: $controlKeyString\nHost URL: $url\nExpected output size (plugSize): $plugSize or $outByteSize bytes\nInput XML: $inputXml\n" ) ; $ this -> execStartTime = microtime ( true ) ; } $ result = $ transport -> send ( $ inputXml , $ outByteSize ) ; if ( $ result == ' ' ) { $ result = '' ; } } if ( $ this -> isDebug ( ) && $ result ) { $ end = microtime ( true ) ; $ elapsed = $ end - $ this -> execStartTime ; $ this -> debugLog ( "Output XML: $result\nExec end: " . date ( "Y-m-d H:i:s" ) . ". Seconds to execute: $elapsed.\n\n" ) ; } return $ result ; } | Send any XML to XMLSERVICE toolkit . The XML doesn t have to represent a program . Was protected ; made public to be usable by applications . |
49,792 | protected function getControlKey ( $ disconnect = false ) { $ key = '' ; if ( $ disconnect ) { return "*immed" ; } if ( trim ( $ this -> getOption ( 'idleTimeout' ) ) != '' ) { $ idleTimeout = $ this -> getOption ( 'idleTimeout' ) ; $ key .= " *idle($idleTimeout/kill)" ; } if ( $ this -> getOption ( 'cdata' ) ) { $ key .= " *cdata" ; } if ( $ this -> isStateless ( ) ) { $ key .= " *here" ; } else { if ( trim ( $ this -> getOption ( 'sbmjobParams' ) ) != '' ) { $ sbmjobParams = $ this -> getOption ( 'sbmjobParams' ) ; $ key .= " *sbmjob($sbmjobParams)" ; } } if ( $ this -> getOption ( 'trace' ) ) { $ key .= " *log" ; } if ( $ this -> getOption ( 'parseOnly' ) ) { $ key .= " *test" ; if ( $ parseDebugLevel = $ this -> getOption ( 'parseDebugLevel' ) ) { $ key .= "($parseDebugLevel)" ; } } if ( $ this -> getOption ( 'license' ) ) { $ key .= " *license" ; } if ( $ this -> getOption ( 'transport' ) ) { $ key .= " *justproc" ; } if ( $ this -> getOption ( 'performance' ) ) { $ key .= " *rpt" ; } if ( $ this -> getOption ( 'timeReport' ) ) { $ key .= " *fly" ; } if ( $ paseCcsid = $ this -> getOption ( 'paseCcsid' ) ) { $ key .= " *pase($paseCcsid)" ; } if ( $ this -> getOption ( 'customControl' ) ) { $ key .= " {$this->getOption('customControl')}" ; } return trim ( $ key ) ; } | construct a string of space - delimited control keys based on properties of this class . |
49,793 | protected function verifyInternalKey ( ) { if ( $ this -> isStateless ( ) ) { $ this -> setInternalKey ( '' ) ; return ; } if ( trim ( $ this -> getInternalKey ( ) ) == '' ) { if ( session_id ( ) != '' ) { $ this -> setInternalKey ( "/tmp/" . session_id ( ) ) ; } else { $ this -> setInternalKey ( "/tmp/" . $ this -> generate_name ( ) ) ; } } } | Ensures that an IPC has been set . If not generate one |
49,794 | static function GenerateErrorParameter ( ) { $ ErrBytes = 144 ; $ ErrBytesAv = 144 ; $ ErrCPF = '0000000' ; $ ErrRes = ' ' ; $ ErrEx = ' ' ; $ ds [ ] = self :: AddParameterInt32 ( 'in' , "Bytes provided" , 'errbytes' , $ ErrBytes ) ; $ ds [ ] = self :: AddParameterInt32 ( 'out' , "Bytes available" , 'err_bytes_avail' , $ ErrBytesAv ) ; $ ds [ ] = self :: AddParameterChar ( 'out' , 7 , "Exception ID" , 'exceptId' , $ ErrCPF ) ; $ ds [ ] = self :: AddParameterChar ( 'out' , 1 , "Reserved" , 'reserved' , $ ErrRes ) ; $ ds [ ] = self :: AddParameterHole ( 'out' , 128 , "Exception data" , 'excData' , $ ErrEx ) ; return $ ds ; } | creates Data structure that going to be used in lot of i5 API s for error handling |
49,795 | public function ParseErrorParameter ( array $ Error ) { $ CPFErr = false ; if ( ! is_array ( $ Error ) ) { return false ; } if ( isset ( $ Error [ 'exceptId' ] ) && ( $ Error [ 'err_bytes_avail' ] > 0 ) ) { $ CPFErr = $ Error [ 'exceptId' ] ; } return $ CPFErr ; } | err_bytes_avail is the official reliable way to check for an error . |
49,796 | static function getConfigValue ( $ heading , $ key , $ default = null ) { if ( ! isset ( self :: $ _config ) ) { self :: $ _config = parse_ini_file ( CONFIG_FILE , true ) ; } if ( isset ( self :: $ _config [ $ heading ] [ $ key ] ) ) { return self :: $ _config [ $ heading ] [ $ key ] ; } elseif ( isset ( $ default ) ) { return $ default ; } else { return false ; } } | return value from toolkit config file or a default value or false if not found . method is static so that it can retain its value from call to call . |
49,797 | public function JobLog ( $ JobName , $ JobUser , $ JobNumber , $ direction = 'L' ) { if ( $ JobName == '' || $ JobUser == '' || $ JobNumber == '' ) { return false ; } $ this -> TmpUserSpace = new TmpUserSpace ( $ this -> ToolkitSrvObj , $ this -> TmpLib ) ; $ FullUSName = $ this -> TmpUserSpace -> getUSFullName ( ) ; $ InputArray [ ] = $ this -> ToolkitSrvObj -> AddParameterChar ( 'input' , 20 , 'USER SPACE NAME' , 'userspacename' , $ FullUSName ) ; $ InputArray [ ] = $ this -> ToolkitSrvObj -> AddParameterChar ( 'input' , 10 , 'JOB NAME' , 'jobname' , $ JobName ) ; $ InputArray [ ] = $ this -> ToolkitSrvObj -> AddParameterChar ( 'input' , 10 , 'USER NAME' , 'username' , $ JobUser ) ; $ dir = 'L' ; if ( strtoupper ( $ direction ) == "N" ) { $ dir = $ direction ; } $ InputArray [ ] = $ this -> ToolkitSrvObj -> AddParameterChar ( 'input' , 6 , 'Job Number' , 'jobnumber' , $ JobNumber ) ; $ InputArray [ ] = $ this -> ToolkitSrvObj -> AddParameterChar ( 'input' , 1 , 'Direction' , 'direction' , $ dir ) ; $ ret_code = '0' ; $ InputArray [ ] = $ this -> ToolkitSrvObj -> AddParameterChar ( 'both' , 1 , 'retcode' , 'retcode' , $ ret_code ) ; $ OutputArray = $ this -> ToolkitSrvObj -> PgmCall ( ZSTOOLKITPGM , $ this -> ToolkitSrvObj -> getOption ( 'HelperLib' ) , $ InputArray , NULL , array ( 'func' => 'JOBLOGINFO' ) ) ; if ( isset ( $ OutputArray [ 'io_param' ] [ 'retcode' ] ) ) { if ( $ OutputArray [ 'io_param' ] [ 'retcode' ] == '1' ) { return false ; } } sleep ( 1 ) ; $ JobLogRows = $ this -> TmpUserSpace -> ReadUserSpace ( 1 , $ this -> TmpUserSpace -> RetrieveUserSpaceSize ( ) ) ; $ this -> TmpUserSpace -> DeleteUserSpace ( ) ; unset ( $ this -> TmpUserSpace ) ; if ( trim ( $ JobLogRows ) != '' ) { $ logArray = str_split ( $ JobLogRows , $ this -> JOBLOG_RECORD_SIZE ) ; return $ logArray ; } else { return false ; } } | it seems that all three parms must be entered ; it s for a specific job . |
49,798 | protected function addOuterTags ( $ inputXml ) { $ finalXml = $ this -> xmlStart ( ) ; $ finalXml .= "\n<script>" ; if ( $ this -> getOption ( 'sbmjobCommand' ) ) { $ sbmJobCommand = $ this -> getOption ( 'sbmjobCommand' ) ; $ finalXml .= "\n<sbmjob>{$sbmJobCommand}</sbmjob>" ; } $ finalXml .= "\n$inputXml" ; $ finalXml .= "\n</script>" ; return $ finalXml ; } | For consistently add commonly used starting and ending tags to input XML |
49,799 | protected function xmlToObj ( $ xml ) { $ xmlobj = simplexml_load_string ( $ xml ) ; if ( ! $ xmlobj instanceof \ SimpleXMLElement ) { $ badXmlLog = '/tmp/bad.xml' ; $ this -> error = "Unable to parse output XML, which has been logged in $badXmlLog. Possible problems: CCSID, encoding, binary data in an alpha field (use binary/BYTE type instead); if < or > are the problem, consider using CDATA tags." ; error_log ( $ xml , 3 , $ badXmlLog ) ; return false ; } return $ xmlobj ; } | convert xml string to simplexml object |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.