idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
34,600 | protected function setTime ( $ token , $ time = 0 ) { if ( $ time == 0 ) { $ time = time ( ) ; } $ this -> timer [ $ token ] = $ time ; } | Saves a time next to a token . This can be use to measure import tasks . |
34,601 | protected function outputMemoryUsage ( ) { $ memory = memory_get_usage ( true ) ; $ unit = array ( 'B' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' ) ; $ memory = round ( $ memory / pow ( 1024 , ( $ i = floor ( log ( $ memory , 1024 ) ) ) ) , 2 ) . ' ' . $ unit [ $ i ] ; $ this -> output ( 'Memory usage: ' . $ memory , self :: OUTPUT_COMMENT ) ; } | Outputs the current memory usage |
34,602 | public function crawl ( ) { $ this -> setTime ( 'start' ) ; $ config = $ this -> getConfig ( ) ; $ host = $ this -> getDataService ( ) -> getHost ( ) ; $ this -> proceedServer ( $ config [ 'Name' ] , $ host ) ; $ this -> proceedProjects ( ) ; $ this -> output ( '' ) ; $ this -> outputHeadline ( 'Export changesets per project' ) ; $ projects = $ this -> getGerritProjectsByServerId ( $ this -> getServerId ( ) ) ; foreach ( $ projects as $ project ) { $ this -> output ( 'Project "' . $ project [ 'name' ] . '" ... Starts' , self :: OUTPUT_COMMENT ) ; $ this -> proceedChangesetsOfProject ( $ host , $ project ) ; $ this -> output ( 'Project "' . $ project [ 'name' ] . '" ... Ends' , self :: OUTPUT_COMMENT ) ; $ this -> outputMemoryUsage ( ) ; $ this -> output ( '' ) ; } $ this -> cleanupTempTables ( ) ; $ this -> setTime ( 'end' ) ; $ this -> outputEndStatistics ( ) ; return true ; } | Entry point for external source code . This method starts to export the data from a whole Gerrit review system |
34,603 | public function proceedChangesetsOfProject ( $ host , array $ project ) { $ dataService = $ this -> getDataService ( ) ; $ dataServiceName = $ dataService -> getName ( ) ; $ this -> cleanupTempTables ( ) ; $ startNum = 0 ; $ sortKey = null ; $ changeSetQueryLimit = $ dataService -> getQueryLimit ( ) ; do { $ endNum = $ startNum + $ changeSetQueryLimit ; $ queryMessage = sprintf ( 'Querying %s via %s for changes %d...%s' , $ host , $ dataServiceName , $ startNum , $ endNum ) ; $ this -> output ( $ queryMessage ) ; $ data = $ dataService -> getChangesets ( $ project [ 'name' ] , $ sortKey , $ startNum ) ; $ queryStatus = $ this -> transferJsonToArray ( array_pop ( $ data ) ) ; $ startNum += $ queryStatus [ 'rowCount' ] ; $ receivedMessage = sprintf ( 'Received %d changes to process' , $ queryStatus [ 'rowCount' ] ) ; $ this -> output ( $ receivedMessage ) ; foreach ( $ data as $ singleChangeset ) { $ changeSet = $ this -> transferJsonToArray ( $ singleChangeset ) ; $ this -> output ( $ changeSet [ 'subject' ] ) ; $ this -> proceedChangeset ( $ changeSet , $ project ) ; } if ( $ queryStatus [ 'rowCount' ] > 0 && $ queryStatus [ 'rowCount' ] < $ changeSetQueryLimit ) { break ; } $ sortKey = $ this -> getLastSortKey ( $ data ) ; } while ( $ queryStatus [ 'rowCount' ] > 0 ) ; $ this -> proceedChangeSetsDependsOnRelation ( ) ; $ this -> proceedChangeSetsNeededByRelation ( ) ; } | Imports all changes from a incoming project . |
34,604 | protected function proceedChangeSetsNeededByRelation ( ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ tmpTable = Database :: TABLE_TMP_DEPENDS_NEEDED ; $ neededByTable = Database :: TABLE_CHANGESET_NEEDEDBY ; $ changeSetTable = Database :: TABLE_CHANGESET ; $ patchSetTable = Database :: TABLE_PATCHSET ; $ query = ' INSERT INTO ' . $ neededByTable . ' (`changeset`, `needed_by`, `tstamp`, `crdate`) SELECT ' . $ changeSetTable . '.`id`, neededByChangeset.`id`, UNIX_TIMESTAMP(), UNIX_TIMESTAMP() FROM ' . $ tmpTable . ' INNER JOIN ' . $ changeSetTable . ' AS neededByChangeset ON ( ' . $ tmpTable . '.`identifier` = neededByChangeset.`identifier` AND ' . $ tmpTable . '.`number` = neededByChangeset.`number` ) INNER JOIN gerrit_patchset ON ( neededByChangeset.`id` = ' . $ patchSetTable . '.`changeset` AND ' . $ patchSetTable . '.`revision` = ' . $ tmpTable . '.`revision` AND ' . $ patchSetTable . '.`ref` = ' . $ tmpTable . '.`ref` ) INNER JOIN ' . $ changeSetTable . ' ON ( ' . $ changeSetTable . '.`id` = ' . $ tmpTable . '.`changeset` ) WHERE ' . $ tmpTable . '.`status` = ' . intval ( Database :: TMP_DEPENDS_NEEDED_STATUS_NEEDEDBY ) . ' GROUP BY ' . $ changeSetTable . '.`id`, neededByChangeset.`id` ON DUPLICATE KEY UPDATE ' . $ neededByTable . '.`tstamp` = UNIX_TIMESTAMP()' ; $ dbHandle -> exec ( $ query ) ; } | Update method to map the neededBy relation from the temp table to the correct changeset table . |
34,605 | protected function proceedChangeSetsDependsOnRelation ( ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ tmpTable = Database :: TABLE_TMP_DEPENDS_NEEDED ; $ changeSetTable = Database :: TABLE_CHANGESET ; $ patchSetTable = Database :: TABLE_PATCHSET ; $ query = ' UPDATE ' . $ tmpTable . ' INNER JOIN ' . $ changeSetTable . ' AS dependsOnChangeset ON ( ' . $ tmpTable . '.`identifier` = dependsOnChangeset.`identifier` AND ' . $ tmpTable . '.`number` = dependsOnChangeset.`number` ) INNER JOIN ' . $ patchSetTable . ' ON ( dependsOnChangeset.`id` = ' . $ patchSetTable . '.`changeset` AND ' . $ patchSetTable . '.`revision` = ' . $ tmpTable . '.`revision` AND ' . $ patchSetTable . '.`ref` = ' . $ tmpTable . '.`ref` ) INNER JOIN ' . $ changeSetTable . ' ON ( ' . $ changeSetTable . '.`id` = ' . $ tmpTable . '.`changeset` ) SET ' . $ changeSetTable . '.`depends_on` = dependsOnChangeset.`id` WHERE ' . $ tmpTable . '.`status` = ' . intval ( Database :: TMP_DEPENDS_NEEDED_STATUS_DEPENDSON ) ; $ dbHandle -> exec ( $ query ) ; } | Update method to map the dependsOn relation from the temp table to the correct changeset table . |
34,606 | protected function proceedTrackingIds ( $ changeSetId , array $ trackingIds ) { $ dataToUpdate = array ( 'referenced_earlier' => 1 ) ; $ where = 'changeset = ' . intval ( $ changeSetId ) ; $ this -> getDatabase ( ) -> updateRecords ( Database :: TABLE_TRACKING_ID , $ dataToUpdate , $ where ) ; foreach ( $ trackingIds as $ trackingId ) { $ system = $ this -> proceedLookupTable ( Database :: TABLE_TRACKING_SYSTEM , 'id' , 'name' , $ trackingId [ 'system' ] ) ; $ trackingIdRow = $ this -> getGerritTrackingIdByIdentifier ( $ changeSetId , $ system , $ trackingId [ 'id' ] ) ; if ( $ trackingIdRow === false ) { $ trackingRow = array ( 'changeset' => $ changeSetId , 'system' => $ system , 'number' => $ trackingId [ 'id' ] ) ; $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_TRACKING_ID , $ trackingRow ) ; } else { $ dataToUpdate = array ( 'referenced_earlier' => 0 ) ; $ this -> getDatabase ( ) -> updateRecord ( Database :: TABLE_TRACKING_ID , $ dataToUpdate , $ trackingIdRow [ 'id' ] ) ; } $ trackingId = $ this -> unsetKeys ( $ trackingId , array ( 'id' , 'system' ) ) ; $ this -> checkIfAllValuesWereProceeded ( $ trackingId , 'Tracking ID' ) ; } } | Proceed tracking ids per changeset . Checks if they are already exists . If not insert them . |
34,607 | protected function getGerritTrackingIdByIdentifier ( $ changeSetId , $ system , $ trackingId ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id`, `changeset`, `system`, `number` FROM ' . Database :: TABLE_TRACKING_ID . ' WHERE `changeset` = :changeset AND `system` = :system AND `number` = :number' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':changeset' , $ changeSetId , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':system' , $ system , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':number' , $ trackingId , \ PDO :: PARAM_STR ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Returns a tracking id by the unique identifier |
34,608 | protected function proceedSubmitRecords ( array $ changeSet ) { if ( is_array ( $ changeSet [ 'submitRecords' ] === false ) ) { return ; } foreach ( $ changeSet [ 'submitRecords' ] as $ submitRecord ) { $ submitRecordData = array ( 'changeset' => $ changeSet [ 'id' ] , 'status' => $ submitRecord [ 'status' ] , ) ; $ wherePart = array ( 'changeset' => $ changeSet [ 'id' ] ) ; $ submitRecordRow = $ this -> getLookupTableValues ( Database :: TABLE_SUBMIT_RECORDS , array ( 'id' ) , $ wherePart ) ; if ( $ submitRecordRow === false ) { $ id = $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_SUBMIT_RECORDS , $ submitRecordData ) ; } else { $ id = $ submitRecordRow [ 'id' ] ; $ this -> getDatabase ( ) -> updateRecord ( Database :: TABLE_SUBMIT_RECORDS , $ submitRecordData , $ submitRecordRow [ 'id' ] ) ; } $ submitRecord = $ this -> unsetKeys ( $ submitRecord , array ( 'status' ) ) ; if ( is_array ( $ submitRecord [ 'labels' ] ) === true ) { $ this -> proceedSubmitRecordLabels ( $ id , $ submitRecord [ 'labels' ] ) ; $ submitRecord = $ this -> unsetKeys ( $ submitRecord , array ( 'labels' ) ) ; } $ this -> checkIfAllValuesWereProceeded ( $ submitRecord , 'Submit record' ) ; } } | Proceeds the submitRecords key of a changeset |
34,609 | protected function proceedSubmitRecordLabels ( $ submitRecordId , array $ submitRecordLabels ) { foreach ( $ submitRecordLabels as $ labelInfo ) { $ by = array ( 'id' => 0 ) ; if ( array_key_exists ( 'by' , $ labelInfo ) === true ) { $ by = $ this -> proceedPerson ( $ labelInfo [ 'by' ] ) ; } $ submitRecordLabelRow = $ this -> getGerritSubmitRecordLabelByIdentifier ( $ submitRecordId , $ labelInfo [ 'label' ] ) ; $ submitRecordLabel = array ( 'submit_record' => $ submitRecordId , 'label' => $ labelInfo [ 'label' ] , 'status' => $ labelInfo [ 'status' ] , 'by' => $ by [ 'id' ] ) ; if ( $ submitRecordLabelRow === false ) { $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_SUBMIT_RECORD_LABELS , $ submitRecordLabel ) ; } else { $ this -> getDatabase ( ) -> updateRecord ( Database :: TABLE_SUBMIT_RECORD_LABELS , $ submitRecordLabelRow , $ submitRecordLabelRow [ 'id' ] ) ; } $ labelInfo = $ this -> unsetKeys ( $ labelInfo , array ( 'label' , 'status' , 'by' ) ) ; $ this -> checkIfAllValuesWereProceeded ( $ labelInfo , 'Submit record label' ) ; } } | Proceed the labels of a submitRecord key of a changeset |
34,610 | protected function proceedChangeSetsDependsOnAndNeededBy ( array $ changeSet ) { $ keysToUnset = array ( 'id' , 'number' , 'revision' , 'ref' ) ; if ( isset ( $ changeSet [ 'neededBy' ] ) === true ) { foreach ( $ changeSet [ 'neededBy' ] as $ neededBy ) { $ neededByData = array ( 'changeset' => $ changeSet [ 'id' ] , 'identifier' => $ neededBy [ 'id' ] , 'number' => $ neededBy [ 'number' ] , 'revision' => $ neededBy [ 'revision' ] , 'ref' => $ neededBy [ 'ref' ] , 'status' => Database :: TMP_DEPENDS_NEEDED_STATUS_NEEDEDBY ) ; $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_TMP_DEPENDS_NEEDED , $ neededByData ) ; $ neededBy = $ this -> unsetKeys ( $ neededBy , $ keysToUnset ) ; $ this -> checkIfAllValuesWereProceeded ( $ neededBy , 'neededBy' ) ; } unset ( $ neededBy ) ; } if ( isset ( $ changeSet [ 'dependsOn' ] ) === true ) { $ keysToUnset [ ] = 'isCurrentPatchSet' ; foreach ( $ changeSet [ 'dependsOn' ] as $ dependsOn ) { $ dependsOnData = array ( 'changeset' => $ changeSet [ 'id' ] , 'identifier' => $ dependsOn [ 'id' ] , 'number' => $ dependsOn [ 'number' ] , 'revision' => $ dependsOn [ 'revision' ] , 'ref' => $ dependsOn [ 'ref' ] , 'is_current_patchset' => ( int ) $ dependsOn [ 'isCurrentPatchSet' ] , 'status' => Database :: TMP_DEPENDS_NEEDED_STATUS_DEPENDSON ) ; $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_TMP_DEPENDS_NEEDED , $ dependsOnData ) ; $ dependsOn = $ this -> unsetKeys ( $ dependsOn , $ keysToUnset ) ; $ this -> checkIfAllValuesWereProceeded ( $ dependsOn , 'dependsOn' ) ; } unset ( $ dependsOn ) ; } } | Proceed dependsOn and neededBy for a single changeset . This is a little bit tricky because there can be a dependsOn reference to a changeset which is not imported yet . |
34,611 | protected function proceedCurrentPatchSet ( array $ changeSet , $ currentPatchSetId ) { $ currentPatchSet = $ changeSet [ 'currentPatchSet' ] ; $ patchSetRow = $ this -> getGerritPatchsetByIdentifier ( $ changeSet [ 'id' ] , $ currentPatchSet [ 'number' ] , $ currentPatchSet [ 'revision' ] , $ currentPatchSet [ 'createdOn' ] ) ; if ( $ patchSetRow [ 'id' ] != $ currentPatchSetId ) { $ updateData = array ( 'current_patchset' => $ patchSetRow [ 'id' ] ) ; $ this -> getDatabase ( ) -> updateRecord ( Database :: TABLE_CHANGESET , $ updateData , $ changeSet [ 'id' ] ) ; } } | Updates the current patch set for this changeset if necessary . |
34,612 | protected function proceedComment ( array $ comment , array $ changeSet , $ key ) { $ reviewer = $ this -> proceedPerson ( $ comment [ 'reviewer' ] ) ; $ commentRecord = $ this -> getGerritCommentByIdentifier ( $ changeSet [ 'id' ] , $ reviewer [ 'id' ] , $ comment [ 'timestamp' ] , $ key ) ; if ( $ commentRecord === false ) { $ commentData = array ( 'changeset' => $ changeSet [ 'id' ] , 'timestamp' => $ comment [ 'timestamp' ] , 'reviewer' => $ reviewer [ 'id' ] , 'message' => $ comment [ 'message' ] , 'number' => $ key ) ; $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_COMMENT , $ commentData ) ; $ comment = $ this -> unsetKeys ( $ comment , array ( 'timestamp' , 'reviewer' , 'message' ) ) ; $ this -> checkIfAllValuesWereProceeded ( $ comment , 'Comment' ) ; } } | Proceeds a single comment . |
34,613 | protected function proceedFileComments ( array $ patchset ) { foreach ( $ patchset [ 'comments' ] as $ comment ) { $ comment [ 'reviewer' ] = $ this -> proceedPerson ( $ comment [ 'reviewer' ] ) ; $ whereParts = array ( 'patchset' => $ patchset [ 'id' ] , 'file' => $ comment [ 'file' ] ) ; $ fileRow = $ this -> getLookupTableValues ( Database :: TABLE_FILES , array ( 'id' ) , $ whereParts ) ; if ( $ fileRow === false ) { $ type = $ this -> proceedLookupTable ( Database :: TABLE_FILEACTION , 'id' , 'name' , 'COMMENTED' ) ; $ fileData = array ( 'patchset' => $ patchset [ 'id' ] , 'file' => $ comment [ 'file' ] , 'file_old' => '' , 'insertions' => 0 , 'deletions' => 0 , 'type' => $ type ) ; $ fileRow [ 'id' ] = $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_FILES , $ fileData ) ; } $ commentRow = array ( 'patchset' => $ patchset [ 'id' ] , 'file' => $ fileRow [ 'id' ] , 'line' => $ comment [ 'line' ] , 'reviewer' => $ comment [ 'reviewer' ] [ 'id' ] , 'message' => $ comment [ 'message' ] , 'message_crc32' => crc32 ( $ comment [ 'message' ] ) ) ; $ fileCommentRow = $ this -> getGerritFileCommentByIdentifier ( $ patchset [ 'id' ] , $ fileRow [ 'id' ] , $ comment [ 'line' ] , $ comment [ 'reviewer' ] [ 'id' ] , $ commentRow [ 'message_crc32' ] ) ; if ( $ fileCommentRow === false ) { $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_FILE_COMMENTS , $ commentRow ) ; } $ comment = $ this -> unsetKeys ( $ comment , array ( 'file' , 'line' , 'reviewer' , 'message' ) ) ; $ this -> checkIfAllValuesWereProceeded ( $ comment , 'File comment' ) ; } } | Proceeds the comments of a single patchset . One patchset can have n comments . |
34,614 | protected function proceedFiles ( array $ patchset ) { if ( array_key_exists ( 'files' , $ patchset ) === false || is_array ( $ patchset [ 'files' ] ) === false ) { return ; } foreach ( $ patchset [ 'files' ] as $ file ) { $ type = $ this -> proceedLookupTable ( Database :: TABLE_FILEACTION , 'id' , 'name' , $ file [ 'type' ] ) ; $ fileData = array ( 'patchset' => $ patchset [ 'id' ] , 'file' => $ file [ 'file' ] , 'file_old' => ( ( array_key_exists ( 'fileOld' , $ file ) === true ) ? $ file [ 'fileOld' ] : '' ) , 'insertions' => $ file [ 'insertions' ] , 'deletions' => $ file [ 'deletions' ] , 'type' => $ type ) ; $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_FILES , $ fileData ) ; $ file = $ this -> unsetKeys ( $ file , array ( 'file' , 'fileOld' , 'type' , 'insertions' , 'deletions' ) ) ; $ this -> checkIfAllValuesWereProceeded ( $ file , 'File' ) ; } } | Imports files per patchset |
34,615 | protected function proceedApproval ( array $ approval , array $ patchset ) { $ by = $ this -> proceedPerson ( $ approval [ 'by' ] ) ; $ approvalData = array ( 'patchset' => $ patchset [ 'id' ] , 'type' => $ approval [ 'type' ] , 'description' => ( ( isset ( $ approval [ 'description' ] ) === true ) ? $ approval [ 'description' ] : '' ) , 'value' => $ approval [ 'value' ] , 'granted_on' => $ approval [ 'grantedOn' ] , 'by' => $ by [ 'id' ] , 'voted_earlier' => 0 ) ; $ approvalRow = $ this -> getGerritApprovalByIdentifier ( $ patchset [ 'id' ] , $ approval [ 'type' ] , $ by [ 'id' ] ) ; if ( $ approvalRow === false ) { $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_APPROVAL , $ approvalData ) ; } else { $ this -> checkIfServersFirstRun ( 'Approval' , 1363897318 , array ( $ approval , $ approvalRow ) ) ; $ this -> getDatabase ( ) -> updateRecord ( Database :: TABLE_APPROVAL , $ approvalData , $ approvalRow [ 'id' ] ) ; } $ approval = $ this -> unsetKeys ( $ approval , array ( 'type' , 'description' , 'value' , 'grantedOn' , 'by' ) ) ; $ this -> checkIfAllValuesWereProceeded ( $ approval , 'Approval' ) ; unset ( $ approval ) ; } | Will proceed a single approval . |
34,616 | protected function proceedPerson ( array $ person ) { if ( array_key_exists ( 'name' , $ person ) === false && array_key_exists ( 'email' , $ person ) === false && array_key_exists ( 'username' , $ person ) === false ) { $ person [ 'name' ] = 'Unknown (Exporter)' ; $ person [ 'email' ] = 'mail@example.org' ; $ person [ 'username' ] = 'Unknown_export_username' ; } if ( array_key_exists ( 'name' , $ person ) === false ) { $ person [ 'name' ] = 'Unknown (Exporter)' ; } if ( array_key_exists ( 'username' , $ person ) === false ) { $ person [ 'username' ] = 'Unknown_export_username' ; } if ( $ person [ 'name' ] === 'Gerrit Code Review' ) { $ person [ 'username' ] = 'Gerrit' ; } $ email = '' ; $ emailPerson = false ; if ( array_key_exists ( 'email' , $ person ) !== false ) { $ email = $ person [ 'email' ] ; $ emailPerson = $ this -> getPersonBy ( 'email' , $ person [ 'email' ] ) ; } if ( $ emailPerson === false ) { $ personByName = false ; if ( $ person [ 'username' ] ) { $ personByName = $ this -> getPersonBy ( 'username' , $ person [ 'username' ] ) ; } elseif ( $ person [ 'name' ] ) { $ personByName = $ this -> getPersonBy ( 'name' , $ person [ 'name' ] ) ; } if ( $ personByName === false ) { $ personData = array ( 'name' => $ person [ 'name' ] , 'username' => $ person [ 'username' ] ) ; $ person [ 'id' ] = $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_PERSON , $ personData ) ; $ emailData = array ( 'person' => $ person [ 'id' ] , 'email' => $ email ) ; $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_EMAIL , $ emailData ) ; } else { $ person [ 'id' ] = $ personByName [ 'id' ] ; $ emailData = array ( 'person' => $ personByName [ 'id' ] , 'email' => $ email ) ; $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_EMAIL , $ emailData ) ; } } else { $ person [ 'id' ] = $ emailPerson [ 'id' ] ; } return $ person ; } | Handles the import or update process of a single person . A person can be determined by name an e - mail - address or by username . |
34,617 | protected function getGerritProjectsByServerId ( $ serverId ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id`, `name` FROM ' . Database :: TABLE_PROJECT . ' WHERE `server_id` = :server_id' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':server_id' , $ serverId , \ PDO :: PARAM_INT ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; } | Returns all projects by server id |
34,618 | protected function getGerritProjectsByName ( $ serverId , array $ names ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ nameList = implode ( ',' , $ names ) ; $ query = 'SELECT `id`, `name` FROM ' . Database :: TABLE_PROJECT . ' WHERE `server_id` = :server_id AND FIND_IN_SET(BINARY `name`, :names) > 0' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':server_id' , $ serverId , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':names' , $ nameList , \ PDO :: PARAM_STR ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; } | Returns all projects from our database for given server id with given names . |
34,619 | public function getGerritProjectById ( $ serverId , $ projectId ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id`, `name` FROM ' . Database :: TABLE_PROJECT . ' WHERE `server_id` = :server_id AND `id` = :id' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':server_id' , $ serverId , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':id' , $ projectId , \ PDO :: PARAM_INT ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Return a single project from our database for given server id with given project id . |
34,620 | protected function getGerritApprovalByIdentifier ( $ patchSetId , $ type , $ by ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id`, `patchset`, `type`, `description`, `value`, `granted_on`, `by` FROM ' . Database :: TABLE_APPROVAL . ' WHERE `patchset` = :patchset AND `type` = :type AND `by` = :by' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':patchset' , $ patchSetId , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':type' , $ type , \ PDO :: PARAM_STR ) ; $ statement -> bindParam ( ':by' , $ by , \ PDO :: PARAM_INT ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Returns a approval by the unique identifier |
34,621 | protected function getGerritPatchsetByIdentifier ( $ changeSetId , $ number , $ revision , $ createdOn ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id`, `changeset`, `number`, `revision`, `ref`, `uploader`, `created_on` FROM ' . Database :: TABLE_PATCHSET . ' WHERE `changeset` = :changeset AND `number` = :number AND `revision` = :revision AND `created_on` = :created_on' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':changeset' , $ changeSetId , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':number' , $ number , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':revision' , $ revision , \ PDO :: PARAM_STR ) ; $ statement -> bindParam ( ':created_on' , $ createdOn , \ PDO :: PARAM_INT ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Returns a patchset by the unique identifier |
34,622 | protected function getGerritSubmitRecordLabelByIdentifier ( $ submitRecordId , $ label ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id`, `submit_record`, `label`, `status`, `by` FROM ' . Database :: TABLE_SUBMIT_RECORD_LABELS . ' WHERE `submit_record` = :submit_record_id AND `label` = :label' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':submit_record_id' , $ submitRecordId , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':label' , $ label , \ PDO :: PARAM_STR ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Returns a submit record label by unique identifier |
34,623 | protected function getGerritFileCommentByIdentifier ( $ patchSetId , $ file , $ line , $ reviewer , $ messageCrc32 ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id`, `patchset`, `file`, `line`, `reviewer`, `message` FROM ' . Database :: TABLE_FILE_COMMENTS . ' WHERE `patchset` = :patchset AND `file` = :file AND `line` = :line AND `reviewer` = :reviewer AND `message_crc32` = :message_crc32' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':patchset' , $ patchSetId , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':file' , $ file , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':line' , $ line , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':reviewer' , $ reviewer , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':message_crc32' , $ messageCrc32 , \ PDO :: PARAM_INT ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Returns a file comment by unique identifier |
34,624 | protected function getGerritCommentByIdentifier ( $ changeSetId , $ reviewer , $ timestamp , $ number ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id`, `changeset`, `timestamp`, `reviewer`, `message` FROM ' . Database :: TABLE_COMMENT . ' WHERE `changeset` = :changeset AND `timestamp` = :timestamp AND `reviewer` = :reviewer AND `number` = :number' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':changeset' , $ changeSetId , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':timestamp' , $ timestamp , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':reviewer' , $ reviewer , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':number' , $ number , \ PDO :: PARAM_STR ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Returns a Comment by the unique identifier |
34,625 | protected function getGerritChangesetByIdentifier ( $ project , $ branch , $ id , $ createdOn ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id`, `project`, `branch`, `topic`, `identifier`, `number`, `subject`, `owner`, `url`, `commit_message`, `created_on`, `last_updated`, `sort_key`, `open`, `status`, `current_patchset` FROM ' . Database :: TABLE_CHANGESET . ' WHERE `project` = :project AND `branch` = :branch AND `identifier` = :id AND `created_on` = :created_on' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ statement -> bindParam ( ':project' , $ project , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':branch' , $ branch , \ PDO :: PARAM_INT ) ; $ statement -> bindParam ( ':id' , $ id , \ PDO :: PARAM_STR ) ; $ statement -> bindParam ( ':created_on' , $ createdOn , \ PDO :: PARAM_INT ) ; $ executeResult = $ statement -> execute ( ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Returns a changeset by the unique identifier |
34,626 | protected function getLookupTableValues ( $ table , array $ selectFields , array $ whereParts ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ whereCondition = $ whereValues = array ( ) ; foreach ( $ whereParts as $ field => $ value ) { $ whereCondition [ ] = '`' . $ field . '` = :' . $ field ; $ whereValues [ ':' . $ field ] = $ value ; } $ query = 'SELECT `' . implode ( '`,`' , $ selectFields ) . '` FROM ' . $ table . ' WHERE ' . implode ( ' AND ' , $ whereCondition ) . ' LIMIT 1' ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ executeResult = $ statement -> execute ( $ whereValues ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult , $ whereValues ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Returns lookup values from a database table |
34,627 | public function proceedServer ( $ name , $ host ) { $ this -> outputHeadline ( 'Proceed Server' ) ; $ this -> output ( 'Server "' . $ name . '" (' . $ host . ')' ) ; $ serverId = $ this -> existsGerritServer ( $ name , $ host ) ; if ( $ serverId === false ) { $ serverData = array ( 'name' => $ name , 'host' => $ host ) ; $ serverId = $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_SERVER , $ serverData ) ; $ this -> setServersFirstRun ( ) ; $ this -> output ( '=> Inserted (ID: ' . $ serverId . ')' ) ; } else { $ this -> output ( '=> Exists' ) ; } $ this -> output ( '' ) ; $ this -> setServerId ( $ serverId ) ; return $ serverId ; } | Checks if the given Gerrit server is known by the database . If the don t know this host we save this to the database . |
34,628 | public function importProject ( array $ project , array & $ parentMapping ) { $ this -> output ( 'Project "' . $ project [ 'name' ] . '"' ) ; $ row = $ this -> existsGerritProject ( $ project [ 'name' ] , $ this -> getServerId ( ) ) ; $ projectRow = $ project ; $ projectRow [ 'server_id' ] = $ this -> getServerId ( ) ; if ( $ row === false ) { $ projectRow [ 'parent' ] = 0 ; $ id = $ this -> getDatabase ( ) -> insertRecord ( Database :: TABLE_PROJECT , $ projectRow ) ; $ this -> output ( '=> Inserted (ID: ' . $ id . ')' ) ; } else { $ this -> checkIfServersFirstRun ( 'Projects' , 1363893021 , $ row ) ; $ id = $ row [ 'id' ] ; unset ( $ row [ 'id' ] ) ; $ diff = array_diff ( $ projectRow , $ row ) ; if ( count ( $ diff ) > 0 ) { $ this -> getDatabase ( ) -> updateRecord ( Database :: TABLE_PROJECT , $ diff , $ id ) ; $ this -> output ( '=> Updated (ID: ' . $ id . ')' ) ; } else { $ this -> output ( '=> Nothing new. Skip it' ) ; } } if ( isset ( $ project [ 'parent' ] ) === true ) { $ parentMapping [ $ project [ 'parent' ] ] [ ] = intval ( $ id ) ; } return $ id ; } | Imports a single project . We save name description and parent project . |
34,629 | protected function existsGerritServer ( $ name , $ host ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'SELECT `id` FROM ' . Database :: TABLE_SERVER . ' WHERE `name` = :name AND `host` = :host LIMIT 1' ; $ values = array ( ':name' => $ name , ':host' => $ host ) ; $ statement = $ dbHandle -> prepare ( $ query ) ; $ executeResult = $ statement -> execute ( $ values ) ; $ statement = $ this -> getDatabase ( ) -> checkQueryError ( $ statement , $ executeResult , $ values ) ; return $ statement -> fetchColumn ( ) ; } | Checks if a Gerrit server is known by our database . |
34,630 | protected function cleanupTempTables ( ) { $ dbHandle = $ this -> getDatabase ( ) -> getDatabaseConnection ( ) ; $ query = 'TRUNCATE ' . Database :: TABLE_TMP_DEPENDS_NEEDED ; $ dbHandle -> query ( $ query ) ; } | Truncates the temp tables |
34,631 | protected function ascertainRoutingData ( ? string $ routeName = null ) : void { if ( ( $ routeName !== null ) && empty ( $ this -> routes [ $ routeName ] ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'Route %s is not registered.' , $ routeName ) ) ; } if ( ( $ this -> dispatcher === null ) || ( $ this -> parsedRoutes === null ) || ( ! empty ( \ array_diff_key ( $ this -> routes , $ this -> parsedRoutes ) ) ) ) { $ routingData = $ this -> cacheStorage -> getItem ( self :: CACHE_KEY ) ; if ( ( $ routingData !== null ) && ( ! empty ( \ array_diff_key ( $ this -> routes , $ routingData [ 1 ] ) ) ) ) { $ routingData = null ; } if ( $ routingData === null ) { $ routingData = $ this -> generateRoutingData ( ) ; $ this -> cacheStorage -> setItem ( self :: CACHE_KEY , $ routingData ) ; } $ this -> dispatcher = new FR \ Dispatcher \ GroupCountBased ( $ routingData [ 0 ] ) ; $ this -> parsedRoutes = $ routingData [ 1 ] ; } } | Ensures that all data required for routing is loaded and valid |
34,632 | private function findFiles ( $ directory , array $ names , array $ ignoreNames ) { $ finder = new Finder ( ) ; $ finder -> files ( ) -> in ( $ directory ) ; foreach ( $ names as $ name ) { $ finder -> name ( $ name ) ; } foreach ( $ ignoreNames as $ name ) { $ finder -> notName ( $ name ) ; } $ finder -> sortByName ( ) ; return $ finder ; } | Find all files to merge . |
34,633 | private function mergeFiles ( $ directory , Finder $ finder , $ noSuffix ) { $ outXml = new fDOMDocument ; $ outXml -> formatOutput = true ; $ outTestSuites = $ outXml -> createElement ( 'testsuites' ) ; $ outXml -> appendChild ( $ outTestSuites ) ; $ outTestSuite = $ outXml -> createElement ( 'testsuite' ) ; $ outTestSuites -> appendChild ( $ outTestSuite ) ; $ tests = 0 ; $ assertions = 0 ; $ failures = 0 ; $ errors = 0 ; $ time = 0 ; foreach ( $ finder as $ file ) { if ( $ this -> isFileEmpty ( $ file ) ) { continue ; } $ inXml = $ this -> loadFile ( $ file -> getRealpath ( ) ) ; foreach ( $ inXml -> query ( '//testsuites/testsuite' ) as $ inElement ) { if ( ! $ noSuffix ) { $ inName = $ inElement -> getAttribute ( 'name' ) ; $ outName = $ inName ; $ suffix = 2 ; while ( $ outTestSuite -> query ( '//testsuite[@name="' . $ outName . '"]' ) -> length !== 0 ) { $ outName = $ inName . '_' . $ suffix ; $ suffix ++ ; } } $ outElement = $ outXml -> importNode ( $ inElement , true ) ; if ( ! $ noSuffix ) { $ outElement -> setAttribute ( 'name' , $ outName ) ; } $ outTestSuite -> appendChild ( $ outElement ) ; $ tests += $ inElement -> getAttribute ( 'tests' ) ; $ assertions += $ inElement -> getAttribute ( 'assertions' ) ; $ failures += $ inElement -> getAttribute ( 'failures' ) ; $ errors += $ inElement -> getAttribute ( 'errors' ) ; $ time += $ inElement -> getAttribute ( 'time' ) ; } } $ outTestSuite -> setAttribute ( 'name' , $ directory ) ; $ outTestSuite -> setAttribute ( 'tests' , $ tests ) ; $ outTestSuite -> setAttribute ( 'assertions' , $ assertions ) ; $ outTestSuite -> setAttribute ( 'failures' , $ failures ) ; $ outTestSuite -> setAttribute ( 'errors' , $ errors ) ; $ outTestSuite -> setAttribute ( 'time' , $ time ) ; return $ outXml ; } | Merge all files . |
34,634 | private function writeFile ( fDOMDocument $ dom , $ filename ) { $ dom -> formatOutput = true ; $ result = $ dom -> save ( $ filename ) ; return ( $ result !== false ) ? true : false ; } | Writes the merged result file . |
34,635 | public function getPrefixedFieldName ( ) { $ field_name = $ this -> field -> getAttribute ( 'field_name' ) ; if ( $ this -> prefix ) { return $ this -> prefix . '.' . $ field_name ; } return $ field_name ; } | Get the field name with prefix applied . |
34,636 | public function getFieldValue ( ) { $ field_name = $ this -> field -> getAttribute ( 'field_name' ) ; $ oldInput = app ( 'session' ) -> getOldInput ( $ this -> getPrefixedFieldName ( ) ) ; if ( $ oldInput === null ) { if ( $ this -> model ) { $ value = $ this -> model -> getAttribute ( $ field_name ) ; if ( $ value !== null ) { return $ value ; } } return $ this -> field -> getAttribute ( 'value' ) ; } return $ oldInput ; } | Get the field value . Prefills with old input if set then attempts to prefill with model . If no inputs found uses Field default . |
34,637 | public function render ( ) { try { return view ( $ this -> getLayout ( ) , $ this -> parseViewParameters ( ) ) -> render ( ) ; } catch ( \ Exception $ e ) { $ previousHandler = set_exception_handler ( function ( ) { } ) ; restore_error_handler ( ) ; call_user_func ( $ previousHandler , $ e ) ; die ; } } | Render the view for the field . |
34,638 | protected function getDefaultViewParameters ( ) { return [ 'layout' => $ this -> getLayout ( ) , 'field_view' => $ this -> getViewPath ( ) . '.' . $ this -> getView ( ) , 'prefixed_field_name' => $ this -> buildPrefixedFieldName ( ) , 'field_id' => $ this -> getFieldId ( ) , 'field_label' => $ this -> getFieldLabel ( ) , 'field_name' => $ this -> getFieldName ( ) , 'field_value' => $ this -> getFieldValue ( ) , 'field_info' => $ this -> getFieldDescription ( ) , 'field_class' => $ this -> getClass ( ) , 'field_parameters' => $ this -> parseFieldParameters ( ) , ] ; } | Get the default parameters to be sent to the field view . |
34,639 | public function buildPrefixedFieldName ( ) { $ field_name = $ this -> field -> getAttribute ( 'field_name' ) ; if ( $ this -> prefix ) { $ adjustedPrefix = str_replace ( '.' , '[' , $ this -> prefix ) ; if ( str_contains ( $ adjustedPrefix , '[' ) ) { $ adjustedPrefix = $ adjustedPrefix . ']' ; } return $ adjustedPrefix . '[' . $ field_name . ']' ; } return $ field_name ; } | Build the field name with prefix applied . |
34,640 | protected function validate ( array & $ data ) { $ messages = [ ] ; if ( ! empty ( $ data [ 'errors' ] ) && ! empty ( $ data [ 'activity' ] ) && ! empty ( $ data [ 'requests' ] ) ) { array_push ( $ messages , [ 'warning' , trans ( 'It is recommended to periodically clean system logs.' ) ] ) ; } $ data = array_merge ( $ data , [ 'messages' => $ messages ] ) ; return $ data ; } | validate logs verification |
34,641 | protected function activeLogs ( Collection $ collection ) { $ return = [ ] ; foreach ( $ collection as $ model ) { $ module = $ model -> component -> name ; if ( ! isset ( $ return [ $ module ] [ $ model -> name ] ) ) { $ return [ $ module ] [ $ model -> name ] = 0 ; } $ return [ $ module ] [ $ model -> name ] += 1 ; } return $ return ; } | get active logs summary |
34,642 | protected function errorLogs ( array $ collection ) { $ return = [ 'total_logs_count' => count ( $ collection ) ] ; $ item = [ ] ; foreach ( $ collection as $ row ) { $ row = array_except ( $ row , 'date' ) ; $ keys = array_keys ( $ row ) ; if ( empty ( $ item ) ) { $ item = array_fill_keys ( $ keys , 0 ) ; } foreach ( $ keys as $ key ) { $ item [ $ key ] += $ row [ $ key ] ; } } return $ return + $ item ; } | get error logs summary |
34,643 | protected function requestLogs ( RequestLogCollection $ collection ) { $ requests = [ 'total' => $ collection -> count ( ) , ] ; $ size = 0 ; $ requestsCount = 0 ; $ lastCreatedDate = 0 ; $ lastUpdatedDate = 0 ; foreach ( $ collection as $ model ) { $ size += $ model -> file ( ) -> getSize ( ) ; $ requestsCount += $ model -> entries ( ) -> count ( ) ; $ createdAt = $ model -> createdAt ( ) -> toDateTimeString ( ) ; if ( $ lastCreatedDate < $ createdAt ) { $ lastCreatedDate = $ createdAt ; } $ updatedAt = $ model -> updatedAt ( ) -> toDateTimeString ( ) ; if ( $ lastUpdatedDate < $ updatedAt ) { $ lastUpdatedDate = $ updatedAt ; } } return $ requests += [ 'size' => $ size , 'requests_count' => $ requestsCount , 'last_created_date' => $ lastCreatedDate , 'last_updated_date' => $ lastUpdatedDate ] ; } | get request logs summary |
34,644 | public function get ( $ address ) { if ( empty ( $ address ) ) { throw new \ Exception ( "Address is required in order to process" ) ; } $ url = $ this -> getServiceUrl ( ) . "&address=" . urlencode ( $ address ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; $ serviceResults = json_decode ( curl_exec ( $ ch ) ) ; if ( $ serviceResults && $ serviceResults -> status === 'OK' ) { $ this -> serviceResults = $ serviceResults ; return new Location ( $ address , $ this -> serviceResults ) ; } return new Location ( $ address , new \ stdClass ) ; } | Sends request to the passed Google Geocode API URL and fetches the address details and returns them |
34,645 | protected function registerMessages ( $ cpt , ArgumentCollection $ args ) { $ method_name = "messages_for_${cpt}" ; $ this -> $ method_name = function ( $ messages ) use ( $ cpt , $ args ) { $ args -> prepareMessages ( ) ; $ messages [ $ cpt ] = $ args -> get ( Argument :: MESSAGES ) ; if ( $ this -> isQueryable ( $ cpt ) ) { $ permalink = $ this -> getPermalink ( ) ; foreach ( $ this -> getMessagesWithViewLink ( ) as $ key ) { $ messages [ $ cpt ] [ $ key ] .= $ this -> getViewLink ( $ permalink , $ args ) ; } foreach ( $ this -> getMessagesWithPreviewLink ( ) as $ key ) { $ messages [ $ cpt ] [ $ key ] .= $ this -> getPreviewLink ( $ permalink , $ args ) ; } } return $ messages ; } ; add_filter ( 'post_updated_messages' , [ $ this , $ method_name ] ) ; } | Register the edit form messages . |
34,646 | public function createBucket ( $ bucket_name ) { if ( $ this -> doesBucketExist ( $ bucket_name ) ) { $ this -> addMessage ( "Bucket $bucket_name already exists" ) ; return true ; } if ( mkdir ( 's3://' . $ bucket_name ) ) { return true ; } else { $ this -> addMessage ( 'Could not create bucket ' . $ bucket_name ) ; return false ; } } | Create a S3 Bucket |
34,647 | public function generateSuccess ( $ id ) { $ message = trans ( 'Report has been created.' ) ; app ( 'antares.messages' ) -> add ( 'success' , $ message ) ; return redirect ( ) -> to ( handles ( 'antares::logger/download/pdf/' . $ id ) ) ; } | when report generation success |
34,648 | protected function setFields ( $ fields ) { if ( is_array ( $ fields ) ) { foreach ( $ fields as $ field ) { if ( ! in_array ( $ field , $ this -> fieldsWhitelist ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The field `%s` was not recognized.' , $ field ) ) ; } } } elseif ( $ fields === true ) { $ fields = $ this -> fieldsWhitelist ; } else { throw new \ InvalidArgumentException ( "The argument passed to setFields was invalid" ) ; } $ this -> setQueryParam ( 'fields' , $ fields ) ; } | Set profile fields to be fetched |
34,649 | public function getObjectsKeys ( $ type = 'all' ) { $ keys = null ; if ( $ type == 'all' ) { $ function = 'array_merge' ; } elseif ( $ type == 'common' ) { $ function = 'array_intersect_key' ; } else { throw new \ InvalidArgumentException ( "Unknown selection type: $type" ) ; } foreach ( $ this -> objects as $ object ) { if ( version_compare ( PHP_VERSION , '5.4.0' , '<' ) ) { $ objectVars = json_decode ( json_encode ( $ object -> jsonSerialize ( ) ) , true ) ; } else { $ objectVars = json_decode ( json_encode ( $ object ) , true ) ; } $ keys = ( $ keys === null ) ? $ objectVars : $ function ( $ keys , $ objectVars ) ; } return array_keys ( $ keys ) ; } | Gets an array of keys existing in objects |
34,650 | public function toArray ( $ associative = true , $ k = null ) { $ keys = \ func_get_args ( ) ; $ associative = array_shift ( $ keys ) ; if ( empty ( $ keys ) ) { $ keys = $ this -> getObjectsKeys ( ) ; } $ return = array ( ) ; $ i = 0 ; foreach ( $ this -> objects as $ key => $ object ) { $ arrayItem = array ( ) ; $ key = ( $ associative ) ? $ key : $ i ++ ; $ j = 0 ; foreach ( $ keys as $ property ) { $ propertyKey = ( $ associative ) ? $ property : $ j ++ ; $ arrayItem [ $ propertyKey ] = ( isset ( $ object -> $ property ) ) ? $ object -> $ property : null ; } $ return [ $ key ] = $ arrayItem ; } return $ return ; } | Gets all objects as an array |
34,651 | public function update ( $ NodeBalancerID , $ Label = null , $ ClientConnThrottle = null ) { return $ this -> call ( 'nodebalancer.update' , [ 'NodeBalancerID' => $ NodeBalancerID , 'Label' => $ Label , 'ClientConnThrottle' => $ ClientConnThrottle , ] ) ; } | Updates a NodeBalancer s properties . |
34,652 | protected function gridFindOne ( $ name ) { try { $ params = [ 'filename' => $ name ] ; $ obj = $ this -> gridFS -> findOne ( $ params ) ; } catch ( ConnectionTimeoutException $ ex ) { throw new ConnectionTimeoutException ( $ ex ) ; } catch ( \ Exception $ ex ) { throw new NotFoundException ( 'Could not find file "' . $ name . '": ' . $ ex -> getMessage ( ) ) ; } return $ obj ; } | finds a file based on filename from gridfs |
34,653 | public function listBlobs ( $ container , $ prefix = '' , $ delimiter = '' ) { $ allFiles = $ this -> gridFind ( ) ; $ return = [ ] ; foreach ( $ allFiles as $ fileObj ) { $ return [ ] = $ this -> getBlobMeta ( $ fileObj ) ; } $ reduced = [ ] ; foreach ( $ return as & $ filterBlob ) { if ( strpos ( $ filterBlob [ 'path' ] , $ prefix ) !== false ) { $ reduced [ ] = $ filterBlob ; } } if ( empty ( $ reduced ) && ! empty ( $ prefix ) ) { return [ ] ; } $ reduced = ( empty ( $ reduced ) ) ? $ return : $ reduced ; return $ this -> filterPaths ( $ prefix , $ delimiter , $ reduced ) ; } | main function to list blobs within a folder etc . |
34,654 | protected function filterPaths ( $ prefix , $ delimiter , $ reducedBlobs ) { $ return = [ ] ; foreach ( $ reducedBlobs as $ reduction ) { if ( $ reduction [ 'name' ] == $ prefix ) { continue ; } else if ( $ delimiter == '/' ) { $ pathCnt = count ( explode ( '/' , $ reduction [ 'path' ] ) ) ; $ prefixCnt = count ( explode ( '/' , $ prefix ) ) ; if ( $ prefixCnt + 1 == $ pathCnt && ( '/' == substr ( $ reduction [ 'path' ] , - 1 ) ) ) { $ return [ ] = $ reduction ; } elseif ( $ prefixCnt == $ pathCnt ) { $ return [ ] = $ reduction ; } } else { $ return [ ] = $ reduction ; } } return $ return ; } | Takes reduced records and filters out subs if delimeter is present indicating full_path = false |
34,655 | public function generate ( $ className , DependencyGraph $ dependencyGraph ) { $ lastSeparatorPos = strrpos ( $ className , '\\' ) ; if ( $ lastSeparatorPos !== false ) { $ namespace = substr ( $ className , 0 , $ lastSeparatorPos ) ; $ shortClassName = substr ( $ className , $ lastSeparatorPos + 1 ) ; } else { $ namespace = '' ; $ shortClassName = $ className ; } $ serviceDefinitions = [ ] ; foreach ( $ dependencyGraph -> getAllObjects ( ) as $ object ) { if ( ! $ object -> getValue ( ) -> isDynamic ( ) ) { $ paramExprs = [ ] ; foreach ( $ object -> getDependencies ( ) as $ dependency ) { $ paramExprs [ ] = $ this -> dumpParamExpr ( $ dependency ) ; } $ serviceDefinitions [ ] = $ this -> dumpServiceDefinition ( $ object , $ paramExprs ) ; } } return $ this -> dumpClass ( $ namespace , $ shortClassName , $ serviceDefinitions ) ; } | Dumps the class definition code which can eval from PHP . |
34,656 | protected function dumpClass ( $ namespace , $ shortClassName , array $ serviceDefinitions ) { $ joinedServiceDefinitions = implode ( "\n" , $ serviceDefinitions ) ; $ namespaceSource = $ namespace !== '' ? "namespace $namespace;\n\n" : '' ; $ classSource = <<<EOLclass $shortClassName implements \Pimple\ServiceProviderInterface{ public function register(\Pimple\Container \$c) {$joinedServiceDefinitions }}EOL ; return $ namespaceSource . $ classSource ; } | Dumps the class definition code . |
34,657 | protected function dumpServiceDefinition ( DependencyObject $ object , array $ paramExprs ) { $ service = $ object -> getValue ( ) ; $ typeName = $ service -> getType ( ) -> getName ( ) ; $ className = $ service -> getClass ( ) -> getName ( ) ; $ joinedParamExprs = implode ( ', ' , $ paramExprs ) ; return <<<EOL \$c['$typeName'] = function(\$c) { return new \\$className($joinedParamExprs); };EOL ; } | Dumps the service definition code . |
34,658 | public function show ( $ model ) { $ this -> breadcrumb -> onActivityDetails ( $ model ) ; $ data = $ model -> toArray ( ) ; return view ( 'antares/logger::admin.activity.show' , compact ( 'data' ) ) ; } | show details about activity log |
34,659 | public function database ( array $ tables ) { $ views = [ ] ; $ others = [ ] ; $ messages = [ ] ; foreach ( $ tables as $ table ) { ( $ table -> Comment == 'VIEW' ) ? array_push ( $ views , [ 'name' => $ table -> Name ] ) : array_push ( $ others , [ 'name' => $ table -> Name , 'rows' => $ table -> Rows , 'create_time' => $ table -> Create_time , 'collation' => $ table -> Collation , 'size' => $ this -> formatSize ( $ table -> Data_length + $ table -> Index_length ) ] ) ; if ( $ table -> Rows > 1000 ) { array_push ( $ messages , [ 'warning' , sprintf ( 'Table %s has too many data. Clean table historical entities to increase system performance.' , $ table -> Name ) ] ) ; } } return $ this -> view ( 'database' , [ 'views' => $ views ] + [ 'tables' => $ others ] + [ 'messages' => $ messages ] ) ; } | report database tables |
34,660 | public function getQueryLimit ( ) { if ( $ this -> queryLimit === null ) { $ this -> setQueryLimit ( $ this -> initQueryLimit ( ) ) ; } return $ this -> queryLimit ; } | Gets the query limit |
34,661 | public function create ( $ script , $ DistributionIDList , $ Label , $ Description = null , $ isPublic = null , $ rev_note = null ) { return $ this -> call ( 'stackscript.create' , [ 'script' => $ script , 'DistributionIDList' => $ DistributionIDList , 'Label' => $ Label , 'Description' => $ Description , 'isPublic' => $ isPublic , 'rev_note' => $ rev_note , ] ) ; } | Create a StackScript . |
34,662 | public function update ( $ StackScriptID , $ script = null , $ DistributionIDList = null , $ Label = null , $ Description = null , $ isPublic = null , $ rev_note = null ) { return $ this -> call ( 'stackscript.update' , [ 'StackScriptID' => $ StackScriptID , 'script' => $ script , 'DistributionIDList' => $ DistributionIDList , 'Label' => $ Label , 'Description' => $ Description , 'isPublic' => $ isPublic , 'rev_note' => $ rev_note , ] ) ; } | Update a StackScript . |
34,663 | public function validate ( $ ccNumber , $ ccValid , $ amount = 1.0 , $ text = null ) { $ service = $ this -> getService ( ) ; $ validMonth = substr ( $ ccValid , 0 , 2 ) ; $ validYear = substr ( $ ccValid , 3 , 4 ) ; $ ccData = new Model \ CreditCardData ( $ ccNumber , $ validMonth , $ validYear ) ; $ validateAction = new Request \ Action \ Validate ( $ service , $ ccData , $ amount , $ text ) ; return $ validateAction -> validate ( ) ; } | Validate credit card information |
34,664 | public function storeHostedData ( $ ccNumber , $ ccValid , $ hostedDataId ) { $ service = $ this -> getService ( ) ; $ validMonth = substr ( $ ccValid , 0 , 2 ) ; $ validYear = substr ( $ ccValid , 3 , 4 ) ; $ ccData = new Model \ CreditCardData ( $ ccNumber , $ validMonth , $ validYear ) ; $ ccItem = new Model \ CreditCardItem ( $ ccData , $ hostedDataId ) ; $ storeAction = new Request \ Action \ StoreHostedData ( $ service , $ ccItem ) ; return $ storeAction -> store ( ) ; } | Store credit card information externally |
34,665 | public function displayHostedData ( $ hostedDataId ) { $ service = $ this -> getService ( ) ; $ storageItem = new Model \ DataStorageItem ( $ hostedDataId ) ; $ displayAction = new Request \ Action \ DisplayHostedData ( $ service , $ storageItem ) ; return $ displayAction -> display ( ) ; } | Display externally stored data |
34,666 | public function validateHostedData ( $ hostedDataId ) { $ service = $ this -> getService ( ) ; $ payment = new Model \ Payment ( $ hostedDataId ) ; $ validateAction = new Request \ Action \ ValidateHostedData ( $ service , $ payment ) ; return $ validateAction -> validate ( ) ; } | Validate externally store data |
34,667 | public function deleteHostedData ( $ hostedDataId ) { $ service = $ this -> getService ( ) ; $ storageItem = new Model \ DataStorageItem ( $ hostedDataId ) ; $ deleteAction = new Request \ Action \ DeleteHostedData ( $ service , $ storageItem ) ; return $ deleteAction -> delete ( ) ; } | Delete externally store data |
34,668 | public function sellUsingHostedData ( $ hostedDataId , $ amount , $ comments = null , $ invoiceNumber = null ) { $ service = $ this -> getService ( ) ; $ payment = new Model \ Payment ( $ hostedDataId , $ amount ) ; if ( ! empty ( $ comments ) || ! empty ( $ invoiceNumber ) ) { $ transactionDetails = new Model \ TransactionDetails ( 'ns1' , $ comments , $ invoiceNumber ) ; } else { $ transactionDetails = null ; } $ sellAction = new Request \ Transaction \ SellHostedData ( $ service , $ payment , $ transactionDetails ) ; return $ sellAction -> sell ( ) ; } | Make a sale using a previously stored credit card information |
34,669 | public function installRecurringPayment ( $ hostedDataId , $ amount , \ DateTime $ startDate , $ count , $ frequency , $ period ) { $ service = $ this -> getService ( ) ; $ paymentInformation = new Model \ RecurringPaymentInformation ( $ startDate , $ count , $ frequency , $ period ) ; $ payment = new Model \ Payment ( $ hostedDataId , $ amount ) ; $ recurringPaymentAction = new Request \ Action \ RecurringPayment \ Install ( $ service , $ payment , $ paymentInformation ) ; return $ recurringPaymentAction -> install ( ) ; } | Install a recurring payment . |
34,670 | public function installOneTimeRecurringPayment ( $ hostedDataId , $ amount ) { return $ this -> installRecurringPayment ( $ hostedDataId , $ amount , new \ DateTime ( ) , 1 , 1 , Model \ RecurringPaymentInformation :: PERIOD_MONTH ) ; } | Install a recurring payment which will only result in a single immediate payment . |
34,671 | public function modifyRecurringPayment ( $ orderId , $ hostedDataId , $ amount , $ startDate , $ count , $ frequency , $ period ) { $ service = $ this -> getService ( ) ; $ paymentInformation = new Model \ RecurringPaymentInformation ( $ startDate , $ count , $ frequency , $ period ) ; $ payment = new Model \ Payment ( $ hostedDataId , $ amount ) ; $ recurringPaymentAction = new Request \ Action \ RecurringPayment \ Modify ( $ service , $ orderId , $ payment , $ paymentInformation ) ; return $ recurringPaymentAction -> modify ( ) ; } | Modify a recurring payment |
34,672 | public function cancelRecurringPayment ( $ orderId ) { $ service = $ this -> getService ( ) ; $ recurringPaymentAction = new Request \ Action \ RecurringPayment \ Cancel ( $ service , $ orderId ) ; return $ recurringPaymentAction -> cancel ( ) ; } | Cancel a recurring payment |
34,673 | private function getService ( ) { if ( $ this -> myService === null ) { $ curlOptions = [ 'url' => $ this -> serviceUrl , 'sslCert' => $ this -> clientCertPath , 'sslKey' => $ this -> clientKeyPath , 'sslKeyPasswd' => $ this -> clientKeyPassPhrase , 'caInfo' => $ this -> serverCert ] ; $ this -> myService = new OrderService ( $ curlOptions , $ this -> apiUser , $ this -> apiPass , $ this -> debug ) ; } return $ this -> myService ; } | Get a handle to the OrderService |
34,674 | public function getPostData ( $ assoc = false ) { $ postData = $ this -> request -> getJsonRawBody ( $ assoc ) ; if ( ! is_object ( $ postData ) && ! $ assoc ) { return new stdClass ( ) ; } if ( ! is_array ( $ postData ) && $ assoc ) { return [ ] ; } return $ postData ; } | Get json raw body data |
34,675 | protected function success ( $ messages = null ) { $ data = $ this -> getStatusData ( 'success' , $ messages ) ; return $ this -> jsonResponse ( $ data , 200 ) ; } | Return a generic success response . |
34,676 | protected function notFound ( $ messages = null ) { $ data = $ this -> getStatusData ( 'not-found' , $ messages ) ; return $ this -> jsonResponse ( $ data , 404 ) ; } | Return a generic not found response . |
34,677 | protected function status ( $ status , $ code ) { $ data = $ this -> getStatusData ( $ status ) ; return $ this -> jsonResponse ( $ data , $ code ) ; } | Return a generic status JSON reply . |
34,678 | protected function getStatusData ( $ status , $ messages = null , $ msgKey = 'messages' ) { $ data = [ 'status' => $ status ] ; if ( $ messages !== null ) { if ( $ messages instanceof MessageProviderInterface ) { $ messages = $ messages -> getMessageBag ( ) ; } if ( $ messages instanceof ArrayableInterface ) { $ messages = $ messages -> toArray ( ) ; } $ data [ $ msgKey ] = ( array ) $ messages ; } return $ data ; } | Get an array of a status message response . |
34,679 | public function details ( $ date , $ level = null ) { $ log = $ this -> getLogOrFail ( $ date ) ; $ levels = $ this -> logViewer -> levelsNames ( ) ; $ entries = $ log -> entries ( is_null ( $ level ) ? 'all' : $ level ) ; return $ this -> presenter -> details ( $ log , $ levels , $ entries , $ level ) ; } | details of log by date |
34,680 | public function delete ( $ date , IndexListener $ listener ) { try { app ( 'antares.logger' ) -> setOld ( [ 'name' => $ this -> logViewer -> get ( $ date ) -> getFilename ( ) ] ) -> keep ( 'high' ) ; $ this -> logViewer -> delete ( $ date ) ; return $ listener -> deleteSuccess ( ) ; } catch ( Exception $ ex ) { return $ listener -> deleteFailed ( ) ; } } | on delete error log |
34,681 | public function download ( $ date ) { app ( 'antares.logger' ) -> setOld ( [ 'name' => $ this -> logViewer -> get ( $ date ) -> getFilename ( ) ] ) -> keep ( 'medium' ) ; return $ this -> logViewer -> download ( $ date ) ; } | on download error log |
34,682 | public function init ( ) { self :: $ customerId = self :: getOption ( 'options_readspeaker-helper-customer-id' ) ; if ( self :: getOption ( 'options_readspeaker-helper-read-wrapper-id' ) ) { self :: $ readWrapperId = self :: getOption ( 'options_readspeaker-helper-read-wrapper-id' ) ; } add_action ( 'wp_enqueue_scripts' , array ( $ this , 'enqueueScripts' ) ) ; switch ( self :: getOption ( 'options_readspeaker-helper-placement' ) ) { case 'the_content' : add_filter ( 'the_content' , function ( $ content ) { global $ wp_query ; if ( ! in_array ( get_post_type ( ) , ( array ) self :: getOption ( 'options_readspeaker-helper-enable-posttypes' ) ) || ! in_the_loop ( ) || ! is_main_query ( ) || is_comment_feed ( ) ) { return $ content ; } do_action ( 'ReadSpeakerHelper/before_the_readspeaker' ) ; return $ this -> getReadSpeakerTag ( ) . '<div id="' . self :: $ readWrapperId . '">' . $ content . '</div>' ; } ) ; break ; } } | Initialize the readspeaker |
34,683 | public static function getPlayButton ( $ classes = array ( ) ) { $ classes = array_merge ( array ( 'readspeaker-play-button' ) , $ classes ) ; $ classes = apply_filters ( 'ReadSpeakerHelper/play_button_class' , $ classes ) ; $ classes = implode ( ' ' , $ classes ) ; $ playButton = '<div class="rsbtn rs_skip rs_preserve"><a id="' . self :: $ playButtonId . '" href="//app-eu.readspeaker.com/cgi-bin/rsent?customerid=' . self :: $ customerId . '&lang=' . get_locale ( ) . '&readid=' . self :: $ readWrapperId . '&url=' . self :: currentUrl ( ) . '" class="' . $ classes . '">' . __ ( 'Listen' , 'readspeaker-helper' ) . '</a></div>' ; return apply_filters ( 'ReadSpeakerPlayer/play_button' , $ playButton ) ; } | Get the play button |
34,684 | protected function execute ( ) { $ response = $ this -> service -> IPGApiAction ( $ this ) ; if ( $ response instanceof Error ) { return $ response ; } if ( $ this -> function === self :: FUNCTION_INSTALL ) { return new Sell ( $ response ) ; } return new ConfirmRecurring ( $ response ) ; } | Execute this action |
34,685 | public function send ( ) { $ url = array_get ( $ this -> config , 'url' ) ; if ( is_null ( $ url ) ) { throw new Exception ( 'Unable to find valid url. Please verify component configuration.' ) ; } $ files = $ this -> getFiles ( ) ; $ token = csrf_token ( ) ; $ fields = array_merge ( [ 'url' => $ this -> url , 'description' => $ this -> description , 'user_id' => auth ( ) -> user ( ) -> id , 'brand_id' => app ( 'antares.memory' ) -> make ( 'primary' ) -> get ( 'brand.default' ) , '_token' => $ token ] , $ files ) ; $ headers [ ] = 'X-CSRF-Token:' . $ token ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ fields ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; $ result = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; $ this -> cleanup ( $ files ) ; if ( ! $ this -> isJsonResponse ( $ result ) ) { throw new Exception ( 'Unable to send exception details to support system.' ) ; } $ response = json_decode ( $ result ) ; if ( isset ( $ response -> id ) && ( int ) $ response -> id <= 0 ) { throw new Exception ( 'Unable to send exception details to support system.' ) ; } return $ this ; } | sends exception details to support system |
34,686 | protected function cleanup ( array $ files = array ( ) ) { if ( empty ( $ files ) ) { return $ this ; } foreach ( $ files as $ file ) { if ( ! file_exists ( $ file -> name ) ) { continue ; } unlink ( $ file -> name ) ; } return $ this ; } | deletes files from temporary directory |
34,687 | protected function getFiles ( ) { $ filename = storage_path ( 'temp' ) . DIRECTORY_SEPARATOR . str_random ( ) . '.html' ; file_put_contents ( $ filename , $ this -> src ) ; $ files = [ $ filename ] ; $ this -> kernelConsole -> call ( 'report:analyzer' ) ; $ analyzerReportFile = trim ( $ this -> kernelConsole -> output ( ) ) ; if ( file_exists ( $ analyzerReportFile ) ) { array_push ( $ files , $ analyzerReportFile ) ; } $ return = [ ] ; foreach ( $ files as $ index => $ file ) { $ return [ "files[{$index}]" ] = new CURLFile ( $ file ) ; } return $ return ; } | get list of files to transfer report exception |
34,688 | public function make ( $ class ) { $ controller = $ this -> container -> make ( $ class ) ; $ controller -> setServer ( $ this -> makeServer ( ) ) ; $ controller -> setView ( $ this -> makeView ( ) ) ; $ controller -> setSession ( $ this -> makeSession ( ) ) ; $ controller -> setUrlGenerator ( $ this -> makeUrlGenerator ( ) ) ; return $ controller ; } | Create and bootstrap the given controller class . |
34,689 | public function parse ( ) { $ modes = array_change_key_case ( config ( "{$this->configBase}.collector.modes" ) , CASE_LOWER ) ; if ( empty ( $ modes ) || ! is_array ( $ modes ) ) { return $ this -> failed ( 'No mode of operation configured, or mode config invalid' ) ; } $ feeds = config ( "{$this->configBase}.feeds" ) ; if ( empty ( $ feeds ) || ! is_array ( $ feeds ) ) { return $ this -> failed ( 'No RBL feeds configured, or feed config invalid' ) ; } foreach ( $ feeds as $ feedName => $ feedConfig ) { $ validator = Validator :: make ( array_merge ( $ feedConfig , [ 'name' => $ feedName ] ) , $ this -> rulesFeed ) ; if ( $ validator -> fails ( ) ) { return $ this -> failed ( implode ( ' ' , $ validator -> messages ( ) -> all ( ) ) ) ; } } $ this -> feeds = $ feeds ; foreach ( $ modes as $ mode ) { if ( ! array_key_exists ( $ mode , $ this -> allowedModes ) ) { return $ this -> failed ( "Configuration error detected. Mode {$mode} is not an option" ) ; } if ( $ this -> allowedModes [ $ mode ] ) { $ config = config ( "{$this->configBase}.collector.{$mode}" ) ; if ( empty ( $ config ) || ! is_array ( $ config ) ) { return $ this -> failed ( "Configuration error detected. The settings for mode {$mode} is empty or not an array" ) ; } foreach ( $ config as $ configElement ) { $ validator = Validator :: make ( [ $ mode => $ configElement ] , [ $ mode => $ this -> rulesConfig [ $ mode ] ] ) ; if ( $ validator -> fails ( ) ) { return $ this -> failed ( implode ( ' ' , $ validator -> messages ( ) -> all ( ) ) ) ; } } } else { continue ; } } switch ( $ mode ) { case "asns" : $ this -> scanAsn ( $ config ) ; break ; case "netblocks" : $ this -> scanNetblock ( $ config ) ; break ; case "ipaddresses" : $ this -> scanAddresses ( $ config ) ; break ; case "tickets" : $ this -> scanTickets ( ) ; break ; } return $ this -> success ( ) ; } | Scan RBL zones |
34,690 | private function scanNetblock ( $ netblocks ) { foreach ( $ netblocks as $ netblock ) { $ range = $ this -> getAddressRange ( $ netblock ) ; $ rangeAddresses = [ ] ; for ( $ pos = $ range [ 'begin' ] ; $ pos <= $ range [ 'end' ] ; $ pos ++ ) { $ ip = long2ip ( $ pos ) ; if ( substr ( $ ip , - 2 ) !== '.0' && substr ( $ ip , - 4 ) !== '.255' ) { $ rangeAddresses [ ] = $ ip ; } } $ this -> scanAddresses ( $ rangeAddresses ) ; } return true ; } | Retrieve a list of addresses based on a netblock and kick off scanAddress |
34,691 | private function getAddressRange ( $ netblock ) { $ t = explode ( '/' , $ netblock ) ; $ addr = $ t [ 0 ] ; $ cidr = $ t [ 1 ] ; $ corr = ( pow ( 2 , 32 ) - 1 ) - ( pow ( 2 , 32 - $ cidr ) - 1 ) ; $ first = ip2long ( $ addr ) & ( $ corr ) ; $ length = pow ( 2 , 32 - $ cidr ) - 1 ; return [ 'begin' => $ first , 'end' => $ first + $ length , ] ; } | Build array with first and last address of a netblock based on CIDR |
34,692 | private function scanTickets ( ) { $ tickets = Ticket :: where ( 'status_id' , '=' , 'OPEN' ) ; foreach ( $ tickets -> get ( ) as $ ticket ) { $ this -> scanAddress ( $ ticket -> ip ) ; } return true ; } | Retrieve a list of addresses based on open tickets and kick off scanAddress |
34,693 | private function scanAddress ( $ address ) { if ( ! filter_var ( $ address , FILTER_VALIDATE_IP ) === false ) { $ addressReverse = implode ( '.' , array_reverse ( preg_split ( '/\./' , $ address ) ) ) ; foreach ( $ this -> feeds as $ feedName => $ feedData ) { $ this -> feedName = $ feedName ; if ( $ this -> isKnownFeed ( ) && $ this -> isEnabledFeed ( ) ) { $ lookup = $ addressReverse . '.' . $ feedData [ 'zone' ] . '.' ; if ( $ result = gethostbyname ( $ lookup ) ) { if ( $ result != $ lookup ) { $ reason = 'SPAM Sending host' ; if ( array_key_exists ( 'default' , $ feedData [ 'codes' ] ) ) { $ reason = $ feedData [ 'codes' ] [ 'default' ] ; } if ( array_key_exists ( $ result , $ feedData [ 'codes' ] ) ) { $ reason = $ feedData [ 'codes' ] [ $ result ] ; } $ incident = new Incident ( ) ; $ incident -> source = $ feedName ; $ incident -> source_id = false ; $ incident -> ip = $ address ; $ incident -> domain = false ; $ incident -> class = $ feedData [ 'class' ] ; $ incident -> type = $ feedData [ 'type' ] ; $ incident -> timestamp = Carbon :: today ( ) -> timestamp ; $ incident -> information = json_encode ( array_merge ( $ feedData [ 'information' ] , [ 'reason' => $ reason ] ) ) ; $ this -> incidents [ ] = $ incident ; } } } } } else { $ this -> warningCount ++ ; } return true ; } | Scan the address using a DNS request |
34,694 | protected function fluentInput ( $ keys = null ) { if ( $ keys !== null ) { $ input = Input :: only ( $ keys ) ; } else { $ input = Input :: all ( ) ; } return $ this -> getTransformedInput ( $ input ) ; } | Get input as a Fluent instance . |
34,695 | protected function getTransformedInput ( $ input ) { $ transformed = new Fluent ( $ input ) ; foreach ( $ this -> transformInput ( new Fluent ( $ input ) ) as $ k => $ v ) { if ( array_key_exists ( $ k , $ input ) ) { if ( $ v instanceof \ Closure ) { $ transformed [ $ k ] = $ v ( $ input [ $ k ] ) ; } else { $ transformed [ $ k ] = $ v ; } } } return $ transformed ; } | Get the transformed input . |
34,696 | protected function getBaseQuery ( ) { $ config = $ this -> getConfig ( ) ; $ connector = $ this -> getConnector ( ) ; $ connector -> reset ( ) ; $ host = $ config [ 'host' ] ; if ( isset ( $ config [ 'user' ] ) === true ) { $ host = $ config [ 'user' ] . '@' . $ host ; } $ connector -> addCommandPart ( $ host ) ; $ connector -> addCommandPart ( 'gerrit' ) ; return $ connector ; } | Gets the base ssh query object for all SSH requests . |
34,697 | public function load ( $ locale , $ delimiter = null ) { if ( ! isset ( $ this -> locales [ $ locale ] ) ) { throw new LocaleNotFoundException ( "The locale '$locale' was not found in this collection." ) ; } if ( ! is_null ( $ delimiter ) ) { $ this -> locales [ $ locale ] -> setDelimiter ( $ delimiter ) ; } $ this -> locales [ $ locale ] -> flatten ( ) ; $ this -> activeLocale = $ locale ; return $ this ; } | Loads a given local to be ready to use . |
34,698 | public function raw ( ) { if ( is_null ( $ this -> activeLocale ) ) { throw new NoLocaleLoadedException ( 'No locale was loaded for this collection.' ) ; } $ locale = $ this -> activeLocale ; return $ this -> locales [ $ locale ] -> raw ( ) ; } | Return the raw strings array from the collection . |
34,699 | public function setArray ( array $ strings , $ locale ) { $ localeObject = new Locale ; $ localeObject -> setLocale ( $ locale ) -> setStrings ( $ strings ) ; $ this -> locales [ $ locale ] = $ localeObject ; return $ this ; } | Sets an array directly into the collection as a given locale . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.