idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
16,700
|
public function editAction ( $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ em -> getRepository ( 'EcommerceBundle:Tax' ) -> find ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find Tax entity.' ) ; } $ editForm = $ this -> createForm ( new TaxType ( ) , $ entity ) ; $ deleteForm = $ this -> createDeleteForm ( $ id ) ; return array ( 'entity' => $ entity , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
|
Displays a form to edit an existing Feature entity .
|
16,701
|
public function deleteAction ( Request $ request , $ id ) { $ form = $ this -> createDeleteForm ( $ id ) ; $ form -> bind ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ em -> getRepository ( 'EcommerceBundle:Tax' ) -> find ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find Tax entity.' ) ; } $ em -> remove ( $ entity ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'info' , 'tax.deleted' ) ; } return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_tax_index' ) ) ; }
|
Deletes a Family entity .
|
16,702
|
public function authenticate ( ) { $ this -> _authenticateSetup ( ) ; $ dqlQuery = $ this -> _authenticateCreateSelect ( ) ; $ resultIdentities = $ this -> _authenticateQueryDql ( $ dqlQuery ) ; if ( ( $ authResult = $ this -> _authenticateValidateResultset ( $ resultIdentities ) ) instanceof \ Zend_Auth_Result ) { return $ authResult ; } if ( true === $ this -> getAmbiguityIdentity ( ) ) { $ validIdentities = array ( ) ; foreach ( $ resultIdentities as $ identity ) { if ( 1 === ( int ) $ identity [ 'zend_auth_credential_match' ] ) { $ validIdentities [ ] = $ identity ; } } $ resultIdentities = $ validIdentities ; } $ authResult = $ this -> _authenticateValidateResult ( array_shift ( $ resultIdentities ) ) ; return $ authResult ; }
|
Defined by Zend_Auth_Adapter_Interface . This method is called to attempt an authentication . Previous to this call this adapter would have already been configured with all necessary information to successfully connect to a database table and attempt to find a record matching the provided identity .
|
16,703
|
protected function _authenticateCreateSelect ( ) { if ( $ this -> credentialTreatment === null ) { $ this -> credentialTreatment = '?' ; } $ select = sprintf ( '(CASE WHEN e.%s = %s THEN 1 ELSE 0 END) as zend_auth_credential_match' , $ this -> credentialColumn , str_replace ( '?' , $ this -> getEm ( ) -> getConnection ( ) -> quote ( $ this -> credential ) , $ this -> credentialTreatment ) ) ; $ qb = $ this -> em -> createQueryBuilder ( ) -> select ( $ select ) -> from ( $ this -> entityName , 'e' ) -> where ( 'e.' . $ this -> identityColumn . ' = :identity' ) ; $ parameters = array ( 'identity' => $ this -> getIdentity ( ) ) ; foreach ( $ this -> conditions as $ condition => $ params ) { $ qb -> andWhere ( 'e.' . $ condition ) ; $ parameters = array_merge ( $ parameters , $ params ) ; } $ qb -> setParameters ( $ parameters ) ; return $ qb -> getQuery ( ) ; }
|
Construct the Doctrine query .
|
16,704
|
protected function _authenticateQueryDql ( \ Doctrine \ ORM \ Query $ dqlQuery ) { try { $ resultIdentities = $ dqlQuery -> getResult ( ) ; } catch ( \ Exception $ e ) { throw new \ Zend_Auth_Adapter_Exception ( 'The supplied parameters to Extlib\Auth\Adapter\Doctrine2 failed to ' . 'produce a valid sql statement, please check table and column names ' . 'for validity.' , 0 , $ e ) ; } return $ resultIdentities ; }
|
Get result identities
|
16,705
|
public function takeScreenshotAfterFailedStep ( AfterStepScope $ event ) { if ( ! $ event -> getTestResult ( ) -> isPassed ( ) ) { if ( $ this -> getSession ( ) -> getDriver ( ) instanceof Selenium2Driver ) { $ stepLine = $ event -> getStep ( ) -> getLine ( ) ; $ time = time ( ) ; $ fileName = "./step-{$stepLine}-{$time}.png" ; if ( is_writable ( '.' ) ) { $ screenshot = $ this -> getSession ( ) -> getDriver ( ) -> getScreenshot ( ) ; $ stepText = $ event -> getStep ( ) -> getText ( ) ; if ( file_put_contents ( $ fileName , $ screenshot ) ) { echo "Screenshot for '{$stepText}' placed in {$fileName}" . PHP_EOL ; } else { echo "Screenshot failed: {$fileName} is not writable." ; } } } } }
|
If using the Selenium2Driver will automatically screenshot any failed steps and save them in the current directory .
|
16,706
|
public function waitForSelectorExistence ( $ cssSelector , $ attempts = 10 , $ waitInterval = 1 ) { $ this -> waitFor ( function ( $ context ) use ( $ cssSelector ) { try { $ context -> assertElementExists ( $ cssSelector ) ; } catch ( ElementNotFoundException $ e ) { return false ; } return true ; } , $ attempts , $ waitInterval ) ; }
|
Runs a wait for until an cssSelector exists on the page . This will pass even if the cssSelector is not visible on the page . It only needs to exist in the DOM .
|
16,707
|
public function waitForSelectorVisibility ( $ cssSelector , $ attempts = 10 , $ waitInterval = 1 ) { $ this -> waitFor ( function ( $ context ) use ( $ cssSelector ) { try { $ context -> assertIsVisible ( $ cssSelector ) ; } catch ( ExpectationException $ e ) { return false ; } return true ; } , $ attempts , $ waitInterval ) ; }
|
Passes when the given css selector is visible on the page .
|
16,708
|
public function waitForAtLeastOneVisibleElementOfType ( $ selectorString ) { $ this -> waitFor ( function ( $ context ) use ( $ selectorString ) { $ page = $ context -> getSession ( ) -> getPage ( ) ; $ nodes = $ page -> findAll ( 'css' , $ selectorString ) ; foreach ( $ nodes as $ node ) { if ( $ node -> isVisible ( ) ) { return true ; } } return false ; } ) ; }
|
Passes when at least one element with the given selector is visible on the page .
|
16,709
|
public function click ( $ cssSelector ) { $ element = $ this -> getElementByCssSelector ( $ cssSelector ) ; $ this -> assert ( $ element != null , "{$cssSelector} not found on the page" ) ; $ element -> click ( ) ; }
|
Click the first element matching the given css selector .
|
16,710
|
public function doubleclick ( $ cssSelector ) { $ element = $ this -> getElementByCssSelector ( $ cssSelector ) ; $ this -> assert ( $ element != null , "{$cssSelector} not found on the page" ) ; $ element -> doubleClick ( ) ; }
|
Doubleclick the first element matching the given css selector .
|
16,711
|
public function selectOptionInDropdownByPosition ( $ dropdownSelectorString , $ position ) { $ select = $ this -> getElementByCssSelector ( $ dropdownSelectorString ) ; $ firstOption = $ this -> getElementByCssSelector ( $ dropdownSelectorString . " option:nth-of-type({$position})" ) ; $ select -> selectOption ( $ firstOption -> getAttribute ( 'value' ) ) ; }
|
Select the first option in a dropdown whatever it may be .
|
16,712
|
public function clickFirstVisibleElementOfType ( $ selectorString ) { $ page = $ this -> getSession ( ) -> getPage ( ) ; $ nodes = $ page -> findAll ( 'css' , $ selectorString ) ; foreach ( $ nodes as $ node ) { if ( $ node -> isVisible ( ) ) { $ node -> click ( ) ; return ; } } throw new ExpectationException ( "No visible {$selectorString} element found." , $ this -> getSession ( ) -> getDriver ( ) ) ; }
|
Click the first visible element matching the css selector .
|
16,713
|
public function isVisible ( $ cssSelector ) { $ session = $ this -> getSession ( ) ; $ page = $ session -> getPage ( ) ; $ pageElement = $ page -> find ( 'css' , $ cssSelector ) ; return $ pageElement == null ? false : $ pageElement -> isVisible ( ) ; }
|
Determine if the specified css selector is visible on the page .
|
16,714
|
public function assertHtmlContentMatches ( $ selectorString , $ expected ) { $ this -> assertEqual ( trim ( $ this -> getHtmlContent ( $ selectorString ) ) , $ expected ) ; }
|
Given a selector verifies that its content matches the expected .
|
16,715
|
public function mapElements ( $ cssSelector , callable $ function ) { $ elements = $ this -> getElementByCssSelector ( $ cssSelector ) ; $ result = array ( ) ; if ( ! empty ( $ elements ) ) { $ result = $ this -> map ( $ elements , $ function ) ; } return $ result ; }
|
Call a function on all elements matching the given selector .
|
16,716
|
public function addChoiceSite ( SiteFormEvent $ event ) { $ builder = $ event -> getBuilder ( ) ; $ subGroupRender = $ builder -> getAttribute ( 'sub_group_render' ) ; $ subGroupRender = array_merge ( $ subGroupRender , array ( 'media' => array ( 'rank' => 2 , 'label' => 'open_orchestra_media_admin.form.site.sub_group.media' , ) , ) ) ; $ builder -> setAttribute ( 'sub_group_render' , $ subGroupRender ) ; $ builder -> addEventSubscriber ( $ this -> mediaLibrarySharingSubscriber ) ; }
|
add choice site to site form
|
16,717
|
public function createDatabase ( $ name , $ charSet = null ) { if ( $ charSet === null ) { $ charSet = self :: DEFAULT_CHARACTER_SET ; } $ stmt = StringUtils :: format ( self :: CREATE_DB_STMT , [ 'name' => $ name , 'charSet' => $ charSet ] ) ; $ this -> db -> exec ( $ stmt ) ; }
|
Create a database with the give name . For now character set is ignored .
|
16,718
|
private static function _load ( $ flat ) { if ( is_array ( $ flat ) && ! is_array ( $ _SESSION [ 'ACL_INFO' ] ) && count ( $ flat ) > 0 ) { $ _SESSION [ 'ACL_INFO' ] = array ( ) ; } ; foreach ( $ flat as $ row ) { if ( ! array_key_exists ( $ row [ 'action' ] , $ _SESSION [ 'ACL_INFO' ] ) ) { $ _SESSION [ 'ACL_INFO' ] [ $ row [ 'action' ] ] = Array ( ) ; } if ( ! array_key_exists ( $ row [ 'objectType' ] , $ _SESSION [ 'ACL_INFO' ] [ $ row [ 'action' ] ] ) ) { $ _SESSION [ 'ACL_INFO' ] [ $ row [ 'action' ] ] [ $ row [ 'objectType' ] ] = Array ( ) ; } ; if ( ! in_array ( $ row [ 'objectId' ] , $ _SESSION [ 'ACL_INFO' ] [ $ row [ 'action' ] ] [ $ row [ 'objectType' ] ] ) ) { $ _SESSION [ 'ACL_INFO' ] [ $ row [ 'action' ] ] [ $ row [ 'objectType' ] ] [ ] = $ row [ 'objectId' ] ; } ; } ; }
|
Load a block of ACL rules to in - memory tree
|
16,719
|
public static function reload ( ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ _SESSION [ 'ACL_INFO' ] = null ; if ( ! array_key_exists ( 'id' , $ _SESSION [ 'user' ] ) ) { return ; } ; $ userId = $ _SESSION [ 'user' ] [ 'id' ] ; $ flat = $ db -> selectArray ( " SELECT action, objectType, objectId FROM acl_users WHERE userId=? " , array ( $ userId ) ) ; self :: _load ( $ flat ) ; $ flat = $ db -> selectArray ( " SELECT action, objectType, objectId FROM users_roles INNER JOIN acl_roles ON acl_roles.role=users_roles.role WHERE users_roles.userId=? " , array ( $ userId ) ) ; self :: _load ( $ flat ) ; $ _SESSION [ 'ACL_ROLES' ] = self :: getRoles ( $ userId ) ; }
|
Re - create in - memory rights tree based on session s current user
|
16,720
|
public static function hasRole ( $ role ) { if ( ! isset ( $ _SESSION [ 'user' ] ) ) { return false ; } ; if ( ! isset ( $ _SESSION [ 'ACL_ROLES' ] ) ) { return false ; } ; return in_array ( $ role , $ _SESSION [ 'ACL_ROLES' ] ) ; }
|
Tests whether current user is a member of specified role
|
16,721
|
public static function can ( $ action , $ objectType = null , $ objectId = null ) { if ( ! isset ( $ _SESSION [ 'ACL_INFO' ] ) ) { return false ; } ; $ acl = $ _SESSION [ 'ACL_INFO' ] ; foreach ( array ( '*' , $ action ) as $ act ) { if ( array_key_exists ( $ act , $ acl ) ) { $ acl2 = $ acl [ $ act ] ; foreach ( array ( '*' , $ objectType ) as $ typ ) { if ( array_key_exists ( $ typ , $ acl2 ) ) { $ acl3 = $ acl2 [ $ typ ] ; if ( in_array ( 0 , $ acl3 ) || in_array ( $ objectId , $ acl3 ) ) { return true ; } ; } ; } ; } ; } ; return false ; }
|
Test whether current user is allowed an action
|
16,722
|
public static function sqlCondition ( $ columnName , $ action , $ objectType = null ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ sqlTRUE = '(1=1)' ; $ sqlFALSE = '(1=2)' ; if ( ! isset ( $ _SESSION [ 'ACL_INFO' ] ) ) { return $ db -> query ( $ sqlFALSE ) ; } ; $ acl = $ _SESSION [ 'ACL_INFO' ] ; $ granted = array ( ) ; foreach ( array ( '*' , $ action ) as $ act ) { if ( array_key_exists ( $ act , $ acl ) ) { $ acl2 = $ acl [ $ act ] ; foreach ( array ( '*' , $ objectType ) as $ typ ) { if ( array_key_exists ( $ typ , $ acl2 ) ) { $ granted = array_merge ( $ granted , $ acl2 [ $ typ ] ) ; } ; } ; } ; } ; if ( in_array ( 0 , $ granted ) ) { return $ db -> query ( $ sqlTRUE ) ; } elseif ( count ( $ granted ) === 1 ) { return $ db -> query ( "{$columnName}=?" , $ granted [ 0 ] ) ; } elseif ( count ( $ granted ) > 0 ) { return $ db -> query ( "{$columnName} IN" ) -> varsClosed ( $ granted ) ; } ; return $ db -> query ( $ sqlFALSE ) ; }
|
Get SQL condition for matching objectIds user has right to
|
16,723
|
public static function grant ( $ userId = null , $ role = null , $ action = null , $ objectType = '*' , $ objectId = 0 ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ success = false ; if ( $ objectId === '' ) { $ objectId = 0 ; } ; if ( $ userId !== null && $ role !== null ) { $ success = $ db -> insert ( 'users_roles' , array ( 'userId' => $ userId , 'role' => $ role ) ) ; } elseif ( $ userId !== null && $ action !== null ) { $ success = $ db -> insert ( 'acl_users' , array ( 'userId' => $ userId , 'action' => $ action , 'objectType' => $ objectType , 'objectId' => $ objectId ) ) ; } elseif ( $ role !== null && $ action !== null ) { $ success = $ db -> insert ( 'acl_roles' , array ( 'role' => $ role , 'action' => $ action , 'objectType' => $ objectType , 'objectId' => $ objectId ) ) ; } ; if ( ( $ userId !== null && ( isset ( $ _SESSION [ 'user' ] ) && $ _SESSION [ 'user' ] [ 'id' ] == $ userId ) ) || ( $ userId === null && $ role !== null && self :: hasRole ( $ role ) ) ) { self :: reload ( ) ; } ; return $ success ; }
|
Grant new right or role membership
|
16,724
|
public static function revoke ( $ userId = null , $ role = null , $ action = null , $ objectType = '*' , $ objectId = 0 ) { global $ PPHP ; $ success = $ db = $ PPHP [ 'db' ] ; if ( $ objectId === '' ) { $ objectId = 0 ; } ; if ( $ userId !== null && $ role !== null ) { $ success = $ db -> exec ( " DELETE FROM users_roles WHERE userId=? AND role=? " , array ( $ userId , $ role ) ) ; } elseif ( $ userId !== null && $ action !== null ) { $ success = $ db -> exec ( " DELETE FROM acl_users WHERE userId=? AND action=? AND objectType=? AND objectId=? " , array ( $ userId , $ action , $ objectType , $ objectId ) ) ; } elseif ( $ role !== null && $ action !== null ) { $ success = $ db -> exec ( " DELETE FROM acl_roles WHERE role=? AND action=? AND objectType=? AND objectId=? " , array ( $ role , $ action , $ objectType , $ objectId ) ) ; } ; if ( ( $ userId !== null && $ _SESSION [ 'user' ] [ 'id' ] == $ userId ) || ( $ role !== null && self :: hasRole ( $ role ) ) ) { self :: reload ( ) ; } ; return $ success ; }
|
Revoke existing right or role membership
|
16,725
|
public static function getRoles ( $ userId ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ roles = $ db -> selectList ( "SELECT role FROM users_roles WHERE userId=? ORDER BY role ASC" , array ( $ userId ) ) ; return $ roles !== false ? $ roles : array ( ) ; }
|
Get roles for a user
|
16,726
|
public static function getRoleACL ( $ role ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ flat = $ db -> selectArray ( " SELECT action, objectType, objectId FROM acl_roles WHERE role=? " , array ( $ role ) ) ; return is_array ( $ flat ) ? $ flat : array ( ) ; }
|
Get permissions associated with a role
|
16,727
|
public static function getUserACL ( $ userId ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ flat = $ db -> selectArray ( " SELECT action, objectType, objectId FROM acl_users WHERE userId=? " , array ( $ userId ) ) ; return is_array ( $ flat ) ? $ flat : array ( ) ; }
|
Get permissions associated with a user
|
16,728
|
public static function getRoleUsers ( $ role ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ out = $ db -> selectList ( " SELECT userId FROM users_roles WHERE role=? ORDER BY userId ASC " , array ( $ role ) ) ; return ( is_array ( $ out ) ? $ out : array ( ) ) ; }
|
List users which have a given role
|
16,729
|
public static function getObjectUsers ( $ action , $ objectType , $ objectId ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ out = $ db -> selectList ( " SELECT userId FROM acl_users WHERE action=? AND objectType=? AND objectId=? ORDER BY userId ASC " , array ( $ action , $ objectType , $ objectId ) ) ; return ( is_array ( $ out ) ? $ out : array ( ) ) ; }
|
List users which have a specific right
|
16,730
|
public static function banUser ( $ id ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ db -> exec ( "DELETE FROM acl_users WHERE userId=?" , array ( $ id ) ) ; $ db -> exec ( "DELETE FROM users_roles WHERE userId=?" , array ( $ id ) ) ; return true ; }
|
When a user is banned remove it from all ACL tables
|
16,731
|
public static function resolveParams ( Container $ container , $ params ) { $ resolvedParams = array ( ) ; foreach ( $ params as $ key => $ param ) { $ resolvedParam = null ; if ( is_array ( $ param ) ) { $ resolvedParam = self :: resolveParams ( $ container , $ param ) ; } else if ( is_string ( $ param ) ) { $ resolvedParam = $ container -> resolve ( $ param ) ; } else { $ resolvedParam = $ param ; } $ resolvedParams [ $ key ] = $ resolvedParam ; } return $ resolvedParams ; }
|
Resolve the params of an array
|
16,732
|
function destroy ( ) { foreach ( $ this as $ k => $ v ) $ this -> _setCookieParam ( $ k , null , - 2628000 ) ; parent :: destroy ( ) ; }
|
Destroy Current Realm Data Source
|
16,733
|
protected function _assertCookieRestriction ( ) { $ stat = false ; if ( php_sapi_name ( ) !== 'cli' ) { if ( headers_sent ( ) ) throw new \ Exception ( 'Headers was sent, cookies must be sent before any output from your script.' ) ; $ stat = true ; } if ( false === $ stat ) throw new \ Exception ( 'Session Cant Be Initialized.' ) ; }
|
Check Cookie Protocol Restriction
|
16,734
|
public function doActivity ( ) { $ context = [ 'activityArn' => $ this -> arn , 'workerName' => $ this -> name ] ; $ this -> cpeLogger -> logOut ( "INFO" , basename ( __FILE__ ) , "Starting '$this->name' activity tasks polling" ) ; do { try { if ( $ this -> debug ) $ this -> cpeLogger -> logOut ( "DEBUG" , basename ( __FILE__ ) , "Polling for '$this->name' activity..." ) ; $ task = $ this -> cpeSfnHandler -> sfn -> getActivityTask ( $ context ) ; } catch ( \ Exception $ e ) { $ this -> cpeLogger -> logOut ( "ERROR" , basename ( __FILE__ ) , "Sfn getActivityTask Failed! " . $ e -> getMessage ( ) , $ this -> logKey ) ; } try { if ( isset ( $ task [ 'taskToken' ] ) && $ task [ 'taskToken' ] != '' ) { $ this -> cpeLogger -> logOut ( "INFO" , basename ( __FILE__ ) , "\033[1mNew activity '$this->name' triggered!\033[0m Token: " . $ task [ 'taskToken' ] . ".\nSee the Log file for this token: " . $ this -> cpeLogger -> logPath ) ; $ this -> logKey = substr ( $ task [ 'taskToken' ] , strlen ( $ task [ 'taskToken' ] ) - 16 , strlen ( $ task [ 'taskToken' ] ) - ( strlen ( $ task [ 'taskToken' ] ) - 16 ) ) ; $ this -> logKey = preg_replace ( '/[\\\\\/\%\[\]\.\(\)-\/]/s' , "_" , $ this -> logKey ) ; $ this -> token = $ task [ 'taskToken' ] ; if ( $ this -> client ) $ this -> client -> logKey = $ this -> logKey ; $ this -> doInputValidation ( $ task [ 'input' ] ) ; if ( $ this -> client ) $ this -> client -> onStart ( $ task ) ; $ result = $ this -> process ( $ task ) ; $ this -> activitySuccess ( $ result ) ; } } catch ( \ Exception $ e ) { $ this -> activityFail ( $ this -> name . "Exception" , $ e -> getMessage ( ) ) ; } finally { if ( ! empty ( $ this -> inputFilePath ) ) { unlink ( $ this -> inputFilePath ) ; $ this -> inputFilePath = null ; } } } while ( 42 ) ; }
|
This must be called fro your activity to start listening for task Perform Sfn long polling and call user callback function when receiving new activity
|
16,735
|
private function doInputValidation ( $ input ) { if ( ! ( $ this -> input = json_decode ( $ input ) ) ) throw new \ SA \ CpeSdk \ CpeException ( "JSON input is invalid!" , self :: INPUT_INVALID ) ; }
|
Perform JSON input validation Decode JSON to Associative array
|
16,736
|
public function activityFail ( $ error = "" , $ cause = "" ) { $ context = [ 'error' => $ error , 'cause' => $ cause , 'taskToken' => $ this -> token ] ; try { $ this -> cpeLogger -> logOut ( "ERROR" , basename ( __FILE__ ) , "\033[1m[$error]\033[0m $cause" , $ this -> logKey ) ; $ this -> cpeSfnHandler -> sfn -> sendTaskFailure ( $ context ) ; if ( $ this -> client ) $ this -> client -> onFail ( $ this -> token , $ error , $ cause ) ; } catch ( \ Exception $ e ) { $ this -> cpeLogger -> logOut ( "ERROR" , basename ( __FILE__ ) , "Unable to send 'Task Failure' to Sfn! " . $ e -> getMessage ( ) , $ this -> logKey ) ; if ( $ this -> client ) $ this -> client -> onException ( $ context , $ e ) ; return false ; } return true ; }
|
Activity failed Called by parent Activity when something went wrong Notifies Sfn that the activity has failed
|
16,737
|
public function activitySuccess ( $ output = '{}' ) { $ context = [ 'output' => $ output , 'taskToken' => $ this -> token ] ; try { $ this -> cpeLogger -> logOut ( "INFO" , basename ( __FILE__ ) , "\033[1mNotify Sfn that activity has completed!\033[0m" , $ this -> logKey ) ; $ this -> cpeSfnHandler -> sfn -> sendTaskSuccess ( $ context ) ; if ( $ this -> client ) $ this -> client -> onSuccess ( $ this -> token , $ output ) ; } catch ( \ Exception $ e ) { $ this -> cpeLogger -> logOut ( "ERROR" , basename ( __FILE__ ) , "Unable to send 'Task success' to Sfn! " . $ e -> getMessage ( ) , $ this -> logKey ) ; if ( $ this -> client ) $ this -> client -> onException ( $ context , $ e ) ; return false ; } return true ; }
|
Activity Success and completed Notifies Sfn that the activity has succeeded Call this from your activity logic once the process is successful . If return false then the call to Sfn sndTaskSuccess failed Try again or throw an exception to mark the Activity as failed
|
16,738
|
public function activityHeartbeat ( $ data = null ) { $ context = [ 'taskToken' => $ this -> token ] ; try { $ this -> cpeLogger -> logOut ( "INFO" , basename ( __FILE__ ) , "\033[1mSending heartbeat to Sfn ...\033[0m" , $ this -> logKey ) ; $ this -> cpeSfnHandler -> sfn -> sendTaskHeartbeat ( $ context ) ; if ( $ this -> client ) $ this -> client -> onHeartbeat ( $ this -> token , $ data ) ; } catch ( \ Exception $ e ) { $ this -> cpeLogger -> logOut ( "ERROR" , basename ( __FILE__ ) , "Unable to send 'Task Heartbeat' to Sfn! " . $ e -> getMessage ( ) , $ this -> logKey ) ; if ( $ this -> client ) $ this -> client -> onException ( $ context , $ e ) ; return false ; } return true ; }
|
Send heartbeat to Sfn to keep the task alive . Call this from your activity logic . If return false then the heartbeat was not sent Try again or throw an exception to mark the Activity as failed
|
16,739
|
public function has_shipping ( $ order ) { $ virtual = true ; foreach ( $ this -> get_all_products_in ( $ order ) as $ product ) { if ( ! $ product -> is_virtual ( ) ) { $ virtual = false ; break ; } } return ! $ virtual ; }
|
Detect if order has shipping product
|
16,740
|
public function get_all_products_in ( $ order ) { $ order = wc_get_order ( $ order ) ; if ( ! $ order ) { return [ ] ; } $ products = [ ] ; foreach ( $ order -> get_items ( ) as $ item ) { $ products [ ] = $ order -> get_product_from_item ( $ item ) ; } return $ products ; }
|
Get all product in order
|
16,741
|
public function card_icons ( ) { $ icons = [ ] ; $ base_url = WC ( ) -> plugin_url ( ) . '/assets/images/icons/credit-cards/' ; $ base_dir = WC ( ) -> plugin_path ( ) . '/assets/images/icons/credit-cards/' ; if ( is_dir ( $ base_dir ) ) { foreach ( scandir ( $ base_dir ) as $ icon ) { if ( preg_match ( '#(.*)\.svg$#' , $ icon , $ matches ) ) { $ icons [ $ matches [ 1 ] ] = $ base_url . $ icon ; } } } return $ icons ; }
|
Get card icon URL .
|
16,742
|
public function card_css ( $ selector = '.wc-credit-card-form-card-number' ) { $ css = <<<CSS{$selector}{ background-repeat: no-repeat; background-position: right .6180469716em center; background-size: 31px 20px;}CSS ; foreach ( $ this -> card_icons ( ) as $ icon => $ url ) { $ css .= <<<CSS{$selector}.{$icon} { background-image: url("{$url}");}CSS ; } return sprintf ( '<style type="text/css">%s</style>' , $ css ) ; }
|
Get style sheet for card input .
|
16,743
|
public function getFilePath ( $ filename ) { if ( ! strpos ( $ filename , '.' ) ) { $ filename .= ".phtml" ; } foreach ( $ this -> config -> getPaths ( ) as $ path ) { $ file = "$path/$filename" ; if ( file_exists ( $ file ) ) { return $ file ; } } throw new FileNotFoundException ( 'File \'' . $ filename . '\' was not found.' ) ; }
|
Returns the path for the given filename .
|
16,744
|
public function setData ( array $ data ) { foreach ( $ this -> getData ( ) -> toArray ( ) as $ key => $ value ) { $ this -> getData ( ) -> offsetUnset ( $ key ) ; } $ this -> addData ( $ data ) ; return $ this ; }
|
Sets the renderer data
|
16,745
|
public function Build ( ) { $ left_menu_output = "<ul class=\"content_left nav-sidebar\">" ; $ main_menus = $ this -> _LoadXml ( ) ; $ left_menu_output .= $ this -> ProcessMainMenus ( $ main_menus ) ; $ left_menu_output .= "</ul>" ; return $ left_menu_output ; }
|
Returns a string representing the left menu
|
16,746
|
private function _LoadXml ( ) { $ xml = new \ DOMDocument ; $ filename = "APP_ROOT_DIR" . \ Puzzlout \ Framework \ Enums \ ApplicationFolderName :: AppsFolderName . $ this -> app -> name ( ) . '/Config/menus.xml' ; if ( file_exists ( $ filename ) ) { $ xml -> load ( $ filename ) ; } else { throw new \ Exception ( "In " . __CLASS__ . "->" . __METHOD__ ) ; } return $ xml -> getElementsByTagName ( "main_menu" ) ; }
|
Load the left menu from xml and returns the data to process The list of DOMElementNode is the list of main menus to display
|
16,747
|
public function isFirstnameSurname ( $ firstName , $ surname ) { $ result = $ this -> model -> where ( 'first_name' , $ firstName ) -> where ( 'surname' , $ surname ) -> first ( ) ; if ( $ result ) { return $ result -> id ; } return false ; }
|
Does a record exist with the given first_name and surname ?
|
16,748
|
public function createNewRecord ( $ data ) { $ people = new $ this -> model ; $ people [ 'user_id' ] = $ data [ 'user_id' ] ; $ people [ 'title' ] = $ data [ 'title' ] ; $ people [ 'salutation' ] = $ data [ 'salutation' ] ; $ people [ 'first_name' ] = $ data [ 'first_name' ] ; $ people [ 'middle_name' ] = $ data [ 'middle_name' ] ; $ people [ 'surname' ] = $ data [ 'surname' ] ; $ people [ 'position' ] = $ data [ 'position' ] ; $ people [ 'description' ] = $ data [ 'description' ] ; $ people [ 'comments' ] = $ data [ 'comments' ] ; $ people [ 'birthday' ] = $ data [ 'birthday' ] ; $ people [ 'anniversary' ] = $ data [ 'anniversary' ] ; $ people [ 'created_at' ] = $ data [ 'created_at' ] ; $ people [ 'created_by' ] = $ data [ 'created_by' ] ; $ people [ 'updated_at' ] = $ data [ 'updated_at' ] ; $ people [ 'updated_by' ] = $ data [ 'updated_by' ] ; $ people [ 'profile' ] = $ data [ 'profile' ] ; $ people [ 'featured_image' ] = $ data [ 'featured_image' ] ; if ( $ people -> save ( ) ) { return $ people -> id ; } return false ; }
|
INSERT INTO peoples
|
16,749
|
public function loadClass ( $ className ) { foreach ( $ this -> definitions as $ def ) { $ nameSpace = $ def -> getNameSpace ( ) ; $ path = $ def -> getPath ( ) ; $ name = $ className ; if ( $ nameSpace ) { $ ns = rtrim ( $ nameSpace , '\\' ) . '\\' ; $ nameLen = strlen ( $ className ) ; $ nsLen = strlen ( $ ns ) ; if ( $ nameLen < $ nsLen || substr ( $ className , 0 , $ nsLen ) !== $ ns ) return false ; $ name = substr ( $ name , $ nsLen ) ; } $ ds = DIRECTORY_SEPARATOR ; $ path = $ path ? $ path . $ ds : '' ; $ path .= str_replace ( [ '_' , '\\' ] , $ ds , $ name ) . '.php' ; if ( ( $ path = stream_resolve_include_path ( $ path ) ) !== false ) include $ path ; if ( class_exists ( $ className , false ) ) return true ; } return false ; }
|
Loads a class based on its class name .
|
16,750
|
public static function findTemplate ( \ Twig_Loader_Filesystem $ filesystem , $ name ) { $ name = self :: normalizeName ( $ name ) ; self :: validateName ( $ name ) ; list ( $ namespace , $ shortname ) = self :: parseName ( $ name ) ; $ paths = $ filesystem -> getPaths ( $ namespace ) ; if ( empty ( $ paths ) ) { throw new Twig_Error_Loader ( sprintf ( 'There are no registered paths for namespace "%s".' , $ namespace ) ) ; } foreach ( $ paths as $ path ) { if ( is_file ( $ path . '/' . $ shortname ) ) { if ( false !== $ realpath = realpath ( $ path . '/' . $ shortname ) ) { return $ realpath ; } return $ path . '/' . $ shortname ; } } throw new Twig_Error_Loader ( sprintf ( 'Unable to find template "%s" (looked into: %s).' , $ name , implode ( ', ' , $ paths ) ) ) ; }
|
Determine the path of a template based on its name
|
16,751
|
public function create ( \ SplFileInfo $ file ) { $ extension = $ file -> getExtension ( ) ; switch ( $ extension ) { case 'css' : return new StylesheetDocument ( ) ; case 'js' : return new JavascriptDocument ( ) ; default : if ( strstr ( $ this -> getMimeType ( $ file ) , 'image' ) ) { return new ImageDocument ( ) ; } return new FileDocument ( ) ; } }
|
Returns a new instance of the Document that matches the type of the file passed in
|
16,752
|
public function getMimeType ( \ SplFileInfo $ file ) { $ fileInfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mimeType = finfo_file ( $ fileInfo , $ file -> getPathname ( ) ) ; finfo_close ( $ fileInfo ) ; return $ mimeType ; }
|
Returns the mime - type of the given file
|
16,753
|
public static function to ( $ type , $ value , $ argNum = 0 , $ pseudoTypes = [ ] ) { try { return lib \ Type :: to ( $ type , $ value , $ pseudoTypes ) ; } catch ( \ LogicException $ exception ) { $ callerInfomation = self :: getCallerInfomation ( ) ; $ errorMessage = $ callerInfomation [ 'function' ] === '__set' ? sprintf ( 'Value set to %s is not of the expected type' , $ callerInfomation [ 'class' ] . '::' . $ callerInfomation [ 'args' ] [ 0 ] ) : sprintf ( 'Argument %d passed to %s is not of the expected type' , $ argNum + 1 , $ callerInfomation [ 'class' ] . '::' . $ callerInfomation [ 'function' ] . '()' ) ; if ( $ exception instanceof \ DomainException ) { throw new \ DomainException ( $ errorMessage , 0 , $ exception ) ; } elseif ( $ exception instanceof \ InvalidArgumentException ) { throw new \ InvalidArgumentException ( $ errorMessage , 0 , $ exception ) ; } else { throw $ exception ; } } }
|
Converts a given value in accordance with a given IDL type .
|
16,754
|
public function requestLine ( ) { $ uri = $ this -> url -> path ( ) ; if ( $ this -> url -> query ( ) ) { $ uri .= '?' . $ this -> url -> query ( ) ; } return sprintf ( '%s %s HTTP/%s' , $ this -> method , $ uri , $ this -> version ) ; }
|
Get request line
|
16,755
|
public function key ( $ key = '' , $ is_option = false ) { return $ this -> get_key ( $ this -> validate_length ( $ key ) , $ is_option ) ; }
|
Returns a Unique Key .
|
16,756
|
public function get_key ( $ key = '' , $ is_option = false ) { if ( true === $ is_option ) { return $ this -> option_prefix . $ key . $ this -> option_surfix ; } return $ this -> transient_prefix . $ key . $ this -> transient_surfix ; }
|
Returns Key Based on Requirement .
|
16,757
|
protected function validate_length ( $ key = '' ) { if ( $ this -> check_length ( $ key ) === false ) { return $ this -> validate_length ( md5 ( $ key ) ) ; } return $ key ; }
|
Validates Key Length if key lenght exceeds it will md5 or returns the orginal key
|
16,758
|
protected function validate_version ( $ value , $ type = '' ) { if ( false === $ value || empty ( $ value ) || is_null ( $ value ) ) { return false ; } if ( 'option' === $ type ) { return version_compare ( $ this -> option_version , $ value , '=' ) ; } return version_compare ( $ this -> transient_version , $ value , '=' ) ; }
|
Validates If Saved Version is same as in the class version .
|
16,759
|
protected function delete_version_issue ( $ key , $ type = '' ) { if ( true === $ this -> option_auto_delete && 'option' === $ type ) { $ this -> delete_option ( $ key ) ; } if ( true === $ this -> transient_auto_delete ) { return $ this -> delete_transient ( $ key ) ; } return false ; }
|
Deletes if cache has any issues .
|
16,760
|
public function getAttribute ( $ name ) { $ result = null ; if ( $ this -> attributeExists ( $ name ) ) { $ result = $ this -> attributes [ $ name ] ; } return $ result ; }
|
Get attribute by name
|
16,761
|
public function getDirtyAttribute ( $ name ) { $ result = null ; if ( $ this -> dirtyAttributeExists ( $ name ) ) { $ result = $ this -> dirtyAttributes [ $ name ] ; } return $ result ; }
|
Get dirty attribute
|
16,762
|
public function propertyExists ( $ name ) { $ properties = $ this -> getProperties ( ) ; return empty ( $ properties ) || in_array ( $ name , $ properties ) ; }
|
Check property exists
|
16,763
|
public function merge ( ValidationException $ object , $ hasMany = false ) { $ alias = $ object -> alias ( ) ; $ this -> _objects [ $ alias ] [ '_hasMany' ] = ( false !== $ hasMany ) ; if ( true === $ hasMany ) { $ this -> _objects [ $ alias ] [ ] = $ object -> objects ( ) ; } elseif ( $ hasMany ) { $ this -> _objects [ $ alias ] [ $ hasMany ] = $ object -> objects ( ) ; } else { $ this -> _objects [ $ alias ] = $ object -> objects ( ) ; } return $ this ; }
|
Merges an ValidationException object into the current exception Useful when you want to combine errors into one array
|
16,764
|
protected function generateErrors ( $ alias , array $ array , $ directory , $ translate ) { $ errors = [ ] ; foreach ( $ array as $ key => $ object ) { if ( is_array ( $ object ) ) { $ errors [ $ key ] = ( $ key === '_external' ) ? $ this -> generateErrors ( $ alias . '/' . $ key , $ object , $ directory , $ translate ) : $ this -> generateErrors ( $ key , $ object , $ directory , $ translate ) ; } elseif ( $ object instanceof Validation ) { if ( null === $ directory ) { $ file = null ; } else { $ file = trim ( $ directory . '/' . $ alias , '/' ) ; } $ errors += $ object -> errors ( $ file , $ translate ) ; } } return $ errors ; }
|
Recursive method to fetch all the errors in this exception
|
16,765
|
public function set ( $ variable , $ value = '' , $ export = false ) { $ line = $ this -> composeLine ( $ variable , $ value , $ export ) ; $ number = $ this -> has ( $ variable ) ? $ this -> line_numbers [ $ variable ] : null ; $ this -> writeLine ( $ line , $ number ) ; $ this -> load ( ) ; return $ line ; }
|
Set an environment variable to a value .
|
16,766
|
protected function writeLine ( $ line , $ number = null ) { $ this -> ensureFileIsWritable ( ) ; if ( is_null ( $ number ) ) { return file_put_contents ( $ this -> filePath , $ line . PHP_EOL , FILE_APPEND ) ; } $ lines = $ this -> readLinesFromFile ( $ this -> filePath ) ; $ lines [ $ number ] = $ line ; return file_put_contents ( $ this -> filePath , implode ( PHP_EOL , $ lines ) ) ; }
|
Write a line to the dotenv file .
|
16,767
|
protected function ensureFileIsWritable ( ) { if ( ( ! is_writable ( $ this -> filePath ) || ! is_file ( $ this -> filePath ) ) && ( ! is_dir ( dirname ( $ this -> filePath ) ) || ! is_writable ( dirname ( $ this -> filePath ) ) ) ) { throw new InvalidPathException ( sprintf ( 'Unable to write the environment file at %s.' , $ this -> filePath ) ) ; } }
|
Ensures the given filePath is writable .
|
16,768
|
protected function composeLine ( $ name , $ value , $ export = false ) { return sprintf ( '%s%s="%s"' , ( $ export ? 'export ' : '' ) , $ name , addcslashes ( $ value , '"\\' ) ) ; }
|
Compose the dotenv line from given input
|
16,769
|
public function Comment ( $ CommentID , $ Verify = TRUE , $ AutoParent = TRUE ) { $ Regarding = $ this -> Regarding ( 'Comment' , $ CommentID , $ Verify ) ; if ( $ Verify && $ AutoParent ) $ Regarding -> AutoParent ( 'discussion' ) ; return $ Regarding ; }
|
Start a RegardingEntity for a comment
|
16,770
|
public function Message ( $ MessageID , $ Verify = TRUE , $ AutoParent = TRUE ) { $ Regarding = $ this -> Regarding ( 'ConversationMessage' , $ MessageID , $ Verify ) ; if ( $ Verify && $ AutoParent ) $ Regarding -> AutoParent ( 'conversation' ) ; return $ Regarding ; }
|
Start a RegardingEntity for a conversation message
|
16,771
|
public function That ( ) { $ Args = func_get_args ( ) ; $ ThingType = array_shift ( $ Args ) ; return call_user_func_array ( array ( $ this , $ ThingType ) , $ Args ) ; }
|
Transparent forwarder to built - in starter methods
|
16,772
|
public function queryHandler ( ) { $ materialIds = array ( ) ; $ matIdQuery = dbQuery ( NavigationMaterial :: class ) ; if ( ! empty ( $ this -> nav ) ) { $ childStructures = array ( $ this -> nav -> id ) ; $ stepChildren = array ( $ this -> nav -> id ) ; while ( dbQuery ( 'structure_relation' ) -> cond ( 'parent_id' , $ stepChildren ) -> fields ( 'child_id' , $ stepChildren ) ) { $ childStructures = array_merge ( $ childStructures , $ stepChildren ) ; } $ matIdQuery -> cond ( 'StructureID' , $ childStructures ) ; } $ matIdQuery -> cond ( 'Active' , 1 ) -> fields ( 'MaterialID' , $ materialIds ) ; empty ( $ materialIds ) ? $ this -> query -> id ( 0 ) : $ this -> query -> id ( $ materialIds ) ; }
|
Function to add query conditions
|
16,773
|
public function setPagerPrefix ( ) { return 'samsoncms_input_material_application/table/' . ( isset ( $ this -> nav ) ? $ this -> nav -> id : '0' ) . '/' . ( isset ( $ this -> search { 0 } ) ? $ this -> search : '0' ) . '/' ; }
|
Function to form pager prefix
|
16,774
|
public function row ( & $ material , \ samson \ pager \ Pager & $ pager = null , $ module = null ) { m ( ) -> view ( $ this -> row_tmpl ) ; return m ( ) -> set ( $ material , 'material' ) -> set ( 'pager' , $ this -> pager ) -> set ( 'structureId' , isset ( $ this -> nav ) ? $ this -> nav -> id : '0' ) -> output ( ) ; }
|
Function to render rows of the table
|
16,775
|
protected function initialize ( ) { $ this -> log ( 'initialisatie' , LOG_DEBUG ) ; $ remote_host = is_array ( $ this -> remote_host ) ? $ this -> remote_host [ 0 ] : $ this -> remote_host ; $ this -> timestamp = time ( ) ; $ this -> remote_target_dir = strtr ( $ this -> remote_dir_format , array ( '%project_name%' => $ this -> project_name , '%timestamp%' => date ( $ this -> remote_dir_timestamp_format , $ this -> timestamp ) ) ) ; if ( $ timestamps = $ this -> findPastDeploymentTimestamps ( $ remote_host , $ this -> remote_dir ) ) { list ( $ this -> previous_timestamp , $ this -> last_timestamp ) = $ timestamps ; } if ( $ this -> previous_timestamp ) { $ this -> previous_remote_target_dir = strtr ( $ this -> remote_dir_format , array ( '%project_name%' => $ this -> project_name , '%timestamp%' => date ( $ this -> remote_dir_timestamp_format , $ this -> previous_timestamp ) ) ) ; } if ( $ this -> last_timestamp ) { $ this -> last_remote_target_dir = strtr ( $ this -> remote_dir_format , array ( '%project_name%' => $ this -> project_name , '%timestamp%' => date ( $ this -> remote_dir_timestamp_format , $ this -> last_timestamp ) ) ) ; } }
|
Determines the timestamp of the new deployment and those of the latest two
|
16,776
|
protected function check ( $ action ) { $ this -> log ( 'check' , LOG_DEBUG ) ; if ( is_array ( $ this -> remote_host ) ) { foreach ( $ this -> remote_host as $ key => $ remote_host ) { if ( $ key == 0 ) continue ; $ this -> prepareRemoteDirectory ( $ remote_host , $ this -> remote_dir ) ; } } if ( $ action == 'update' ) $ this -> checkFiles ( is_array ( $ this -> remote_host ) ? $ this -> remote_host [ 0 ] : $ this -> remote_host , $ this -> remote_dir , $ this -> last_remote_target_dir ) ; if ( $ action == 'update' ) { if ( is_array ( $ this -> remote_host ) ) { foreach ( $ this -> remote_host as $ remote_host ) { if ( $ files = $ this -> listFilesToRename ( $ remote_host , $ this -> remote_dir ) ) { $ this -> log ( "Target-specific file renames on $remote_host:" ) ; foreach ( $ files as $ filepath => $ newpath ) $ this -> log ( " $newpath => $filepath" ) ; } } } else { if ( $ files = $ this -> listFilesToRename ( $ this -> remote_host , $ this -> remote_dir ) ) { $ this -> log ( 'Target-specific file renames:' ) ; foreach ( $ files as $ filepath => $ newpath ) $ this -> log ( " $newpath => $filepath" ) ; } } } if ( $ action == 'update' ) return static :: inputPrompt ( 'Proceed with deployment? (yes/no): ' , 'no' ) == 'yes' ; elseif ( $ action == 'rollback' ) return static :: inputPrompt ( 'Proceed with rollback? (yes/no): ' , 'no' ) == 'yes' ; return false ; }
|
Run a dry - run to the remote server to show the changes to be made
|
16,777
|
public function rollback ( ) { $ this -> log ( 'rollback' , LOG_DEBUG ) ; if ( ! $ this -> previous_remote_target_dir ) { $ this -> log ( 'Rollback impossible, no previous deployment found !' ) ; return ; } if ( ! $ this -> check ( 'rollback' ) ) return ; if ( is_array ( $ this -> remote_host ) ) { foreach ( $ this -> remote_host as $ remote_host ) { $ this -> preRollback ( $ remote_host , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; $ this -> changeSymlink ( $ remote_host , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; } $ this -> postDeactivation ( $ this -> remote_host [ 0 ] , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; foreach ( $ this -> remote_host as $ remote_host ) { $ this -> clearRemoteCaches ( $ remote_host , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; $ this -> postRollback ( $ remote_host , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; } foreach ( $ this -> remote_host as $ remote_host ) { $ this -> rollbackFiles ( $ remote_host , $ this -> remote_dir , $ this -> last_remote_target_dir ) ; } } else { $ this -> preRollback ( $ this -> remote_host , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; $ this -> changeSymlink ( $ this -> remote_host , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; $ this -> postDeactivation ( $ this -> remote_host , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; $ this -> clearRemoteCaches ( $ this -> remote_host , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; $ this -> postRollback ( $ this -> remote_host , $ this -> remote_dir , $ this -> previous_remote_target_dir ) ; $ this -> rollbackFiles ( $ this -> remote_host , $ this -> remote_dir , $ this -> last_remote_target_dir ) ; } }
|
Draait de laatste deployment terug
|
16,778
|
public function cleanup ( ) { $ this -> log ( 'cleanup' , LOG_DEBUG ) ; $ past_deployments = array ( ) ; if ( is_array ( $ this -> remote_host ) ) { foreach ( $ this -> remote_host as $ remote_host ) { if ( $ past_dirs = $ this -> collectPastDeployments ( $ remote_host , $ this -> remote_dir ) ) { $ past_deployments [ ] = array ( 'remote_host' => $ remote_host , 'remote_dir' => $ this -> remote_dir , 'dirs' => $ past_dirs ) ; } } } else { if ( $ past_dirs = $ this -> collectPastDeployments ( $ this -> remote_host , $ this -> remote_dir ) ) { $ past_deployments [ ] = array ( 'remote_host' => $ this -> remote_host , 'remote_dir' => $ this -> remote_dir , 'dirs' => $ past_dirs ) ; } } if ( ! empty ( $ past_deployments ) ) { if ( static :: inputPrompt ( 'Delete old directories? (yes/no): ' , 'no' ) == 'yes' ) $ this -> deletePastDeployments ( $ past_deployments ) ; } else { $ this -> log ( 'No cleanup needed' ) ; } }
|
Deletes obsolete deployment directories
|
16,779
|
protected function updateFiles ( $ remote_host , $ remote_dir , $ target_dir ) { $ this -> log ( 'updateFiles' , LOG_DEBUG ) ; $ this -> rsyncExec ( $ this -> rsync_path . ' --rsh="ssh -p ' . $ this -> remote_port . '" -azcO --force --delete --progress ' . $ this -> prepareExcludes ( ) . ' ' . $ this -> prepareLinkDest ( $ remote_dir ) . ' ./ ' . $ this -> remote_user . '@' . $ remote_host . ':' . $ remote_dir . '/' . $ target_dir ) ; $ this -> fixDatadirSymlinks ( $ remote_host , $ remote_dir , $ target_dir ) ; $ this -> renameTargetFiles ( $ remote_host , $ remote_dir ) ; }
|
Uploads files to the new directory on the remote server
|
16,780
|
protected function fixDatadirSymlinks ( $ remote_host , $ remote_dir , $ target_dir ) { $ this -> log ( 'fixDatadirSymlinks' , LOG_DEBUG ) ; if ( empty ( $ this -> data_dirs ) ) return ; $ this -> log ( 'Creating data dir symlinks:' , LOG_DEBUG ) ; $ cmd = "cd $remote_dir/{$target_dir}; php {$this->datadir_patcher} --datadir-prefix={$this->data_dir_prefix} --previous-dir={$this->last_remote_target_dir} " . implode ( ' ' , $ this -> data_dirs ) ; $ output = array ( ) ; $ return = null ; $ this -> sshExec ( $ remote_host , $ cmd , $ output , $ return ) ; $ this -> log ( $ output ) ; }
|
Executes the datadir patcher to create symlinks to the data dirs .
|
16,781
|
protected function restartGearmanWorkers ( $ remote_host , $ remote_dir , $ target_dir ) { $ this -> log ( "restartGearmanWorkers($remote_host, $remote_dir, $target_dir)" , LOG_DEBUG ) ; if ( ! isset ( $ this -> gearman [ 'workers' ] ) || empty ( $ this -> gearman [ 'workers' ] ) ) return ; $ cmd = "cd $remote_dir/{$target_dir}; " ; foreach ( $ this -> gearman [ 'servers' ] as $ server ) { foreach ( $ this -> gearman [ 'workers' ] as $ worker ) { $ worker = sprintf ( $ worker , $ this -> target ) ; $ cmd .= "php {$this->gearman_restarter} --ip={$server['ip']} --port={$server['port']} --function=$worker; " ; } } $ output = array ( ) ; $ return = null ; $ this -> sshExec ( $ remote_host , $ cmd , $ output , $ return ) ; }
|
Gearman workers herstarten
|
16,782
|
protected function rollbackFiles ( $ remote_host , $ remote_dir , $ target_dir ) { $ this -> log ( 'rollbackFiles' , LOG_DEBUG ) ; $ output = array ( ) ; $ return = null ; $ this -> sshExec ( $ remote_host , 'cd ' . $ remote_dir . '; rm -rf ' . $ target_dir , $ output , $ return ) ; }
|
Verwijdert de laatst geuploadde directory
|
16,783
|
protected function listFilesToRename ( $ remote_host , $ remote_dir ) { if ( ! isset ( $ this -> files_to_rename [ "$remote_host-$remote_dir" ] ) ) { $ target_files_to_move = array ( ) ; if ( ! empty ( $ this -> target_specific_files ) ) { foreach ( $ this -> target_specific_files as $ filepath ) { $ ext = pathinfo ( $ filepath , PATHINFO_EXTENSION ) ; if ( isset ( $ target_files_to_move [ $ filepath ] ) ) { $ target_filepath = str_replace ( ".$ext" , ".{$this->target}.$ext" , $ target_files_to_move [ $ filepath ] ) ; } else { $ target_filepath = str_replace ( ".$ext" , ".{$this->target}.$ext" , $ filepath ) ; } $ target_files_to_move [ $ filepath ] = $ target_filepath ; } } if ( ! empty ( $ target_files_to_move ) ) { foreach ( $ target_files_to_move as $ current_filepath ) { if ( ! file_exists ( $ current_filepath ) ) { throw new DeployException ( "$current_filepath does not exist" ) ; } } } $ this -> files_to_rename [ "$remote_host-$remote_dir" ] = $ target_files_to_move ; } return $ this -> files_to_rename [ "$remote_host-$remote_dir" ] ; }
|
Maakt een lijst van de files die specifiek zijn voor een clusterrol of doel en op de doelserver hernoemd moeten worden
|
16,784
|
protected function prepareExcludes ( ) { $ this -> log ( 'prepareExcludes' , LOG_DEBUG ) ; chdir ( $ this -> basedir ) ; $ exclude_param = '' ; if ( count ( $ this -> rsync_excludes ) > 0 ) { foreach ( $ this -> rsync_excludes as $ exclude ) { if ( ! file_exists ( $ exclude ) ) { throw new DeployException ( 'Rsync exclude file not found: ' . $ exclude ) ; } $ exclude_param .= '--exclude-from=' . escapeshellarg ( $ exclude ) . ' ' ; } } if ( ! empty ( $ this -> data_dirs ) ) { foreach ( $ this -> data_dirs as $ data_dir ) { $ exclude_param .= '--exclude ' . escapeshellarg ( "/$data_dir" ) . ' ' ; } } return $ exclude_param ; }
|
Zet het array van rsync excludes om in een lijst rsync parameters
|
16,785
|
protected function prepareRemoteDirectory ( $ remote_host , $ remote_dir ) { $ this -> log ( 'Initialize remote directory: ' . $ remote_host . ':' . $ remote_dir , LOG_INFO , true ) ; $ output = array ( ) ; $ return = null ; $ this -> sshExec ( $ remote_host , "mkdir -p $remote_dir" , $ output , $ return , '' , '' , LOG_DEBUG ) ; if ( empty ( $ this -> data_dirs ) ) return ; $ data_dirs = count ( $ this -> data_dirs ) > 1 ? '{' . implode ( ',' , $ this -> data_dirs ) . '}' : implode ( ',' , $ this -> data_dirs ) ; $ cmd = "mkdir -v -m 0775 -p $remote_dir/{$this->data_dir_prefix}/$data_dirs" ; $ output = array ( ) ; $ return = null ; $ this -> sshExec ( $ remote_host , $ cmd , $ output , $ return , '' , '' , LOG_DEBUG ) ; }
|
Initializes the remote project and data directories .
|
16,786
|
protected function findPastDeploymentTimestamps ( $ remote_host , $ remote_dir ) { $ this -> log ( 'findPastDeploymentTimestamps' , LOG_DEBUG ) ; $ this -> prepareRemoteDirectory ( $ remote_host , $ remote_dir ) ; if ( $ remote_dir === null ) $ remote_dir = $ this -> remote_dir ; $ dirs = array ( ) ; $ return = null ; $ this -> sshExec ( $ remote_host , "ls -1 $remote_dir" , $ dirs , $ return , '' , '' , LOG_DEBUG ) ; if ( $ return !== 0 ) throw new DeployException ( 'ssh initialize failed' ) ; if ( ! count ( $ dirs ) ) return null ; $ past_deployments = array ( ) ; $ deployment_timestamps = array ( ) ; foreach ( $ dirs as $ dirname ) { if ( preg_match ( '/' . preg_quote ( $ this -> project_name ) . '_\d{4}-\d{2}-\d{2}_\d{6}/' , $ dirname ) && ( $ time = strtotime ( str_replace ( array ( $ this -> project_name . '_' , '_' ) , array ( '' , ' ' ) , $ dirname ) ) ) ) { $ past_deployments [ ] = $ dirname ; $ deployment_timestamps [ ] = $ time ; } } $ count = count ( $ deployment_timestamps ) ; if ( $ count == 0 ) return null ; $ this -> log ( 'Past deployments:' , LOG_INFO , true ) ; $ this -> log ( $ past_deployments , LOG_INFO , true ) ; sort ( $ deployment_timestamps ) ; if ( $ count >= 2 ) return array_slice ( $ deployment_timestamps , - 2 ) ; return array ( null , array_pop ( $ deployment_timestamps ) ) ; }
|
Returns the timestamps of the second latest and latest deployments
|
16,787
|
protected function collectPastDeployments ( $ remote_host , $ remote_dir ) { $ this -> log ( 'collectPastDeployments' , LOG_DEBUG ) ; $ dirs = array ( ) ; $ return = null ; $ this -> sshExec ( $ remote_host , "ls -1 $remote_dir" , $ dirs , $ return ) ; if ( $ return !== 0 ) { throw new DeployException ( 'ssh initialize failed' ) ; } if ( ! count ( $ dirs ) ) return null ; $ deployment_dirs = array ( ) ; foreach ( $ dirs as $ dirname ) { if ( preg_match ( '/' . preg_quote ( $ this -> project_name ) . '_\d{4}-\d{2}-\d{2}_\d{6}/' , $ dirname ) ) { $ deployment_dirs [ ] = $ dirname ; } } if ( count ( $ deployment_dirs ) <= 2 ) return null ; $ dirs_to_delete = array ( ) ; sort ( $ deployment_dirs ) ; $ deployment_dirs = array_slice ( $ deployment_dirs , 0 , - 2 ) ; foreach ( $ deployment_dirs as $ key => $ dirname ) { $ time = strtotime ( str_replace ( array ( $ this -> project_name . '_' , '_' ) , array ( '' , ' ' ) , $ dirname ) ) ; if ( $ time < strtotime ( '-1 month' ) ) { $ this -> log ( "$dirname is older than a month" ) ; $ dirs_to_delete [ ] = $ dirname ; } elseif ( $ time < strtotime ( '-1 week' ) ) { if ( isset ( $ deployment_dirs [ $ key + 1 ] ) ) { $ time_next = strtotime ( str_replace ( array ( $ this -> project_name . '_' , '_' ) , array ( '' , ' ' ) , $ deployment_dirs [ $ key + 1 ] ) ) ; if ( date ( 'j' , $ time_next ) == date ( 'j' , $ time ) ) { $ this -> log ( "$dirname was replaced the same day" ) ; $ dirs_to_delete [ ] = $ dirname ; } else { $ this -> log ( "$dirname stays" ) ; } } } else { $ this -> log ( "$dirname stays" ) ; } } return $ dirs_to_delete ; }
|
Returns all obsolete deployments that can be deleted .
|
16,788
|
protected function deletePastDeployments ( $ past_deployments ) { foreach ( $ past_deployments as $ past_deployment ) { $ this -> rollbackFiles ( $ past_deployment [ 'remote_host' ] , $ past_deployment [ 'remote_dir' ] , implode ( ' ' , $ past_deployment [ 'dirs' ] ) ) ; } }
|
Deletes obsolete deployments as collected by collectPastDeployments
|
16,789
|
protected function sshExec ( $ remote_host , $ command , & $ output , & $ return , $ hide_pattern = '' , $ hide_replacement = '' , $ ouput_loglevel = LOG_INFO ) { $ cmd = $ this -> ssh_path . ' -p ' . $ this -> remote_port . ' ' . $ this -> remote_user . '@' . $ remote_host . ' "' . str_replace ( '"' , '\"' , $ command ) . '"' ; if ( $ hide_pattern != '' ) { $ show_cmd = preg_replace ( $ hide_pattern , $ hide_replacement , $ cmd ) ; } else { $ show_cmd = $ cmd ; } $ this -> log ( 'sshExec: ' . $ show_cmd , $ ouput_loglevel ) ; exec ( $ cmd , $ output , $ return ) ; }
|
Wrapper for SSH command s
|
16,790
|
protected function rsyncExec ( $ command , $ error_msg = 'Rsync has failed' ) { $ this -> log ( 'execRSync: ' . $ command , LOG_DEBUG ) ; chdir ( $ this -> basedir ) ; passthru ( $ command , $ return ) ; $ this -> log ( '' ) ; if ( $ return !== 0 ) { throw new DeployException ( $ error_msg ) ; } }
|
Wrapper for rsync command s
|
16,791
|
static protected function inputPrompt ( $ message , $ default = '' , $ isPassword = false ) { fwrite ( STDOUT , $ message ) ; if ( ! $ isPassword ) { $ input = trim ( fgets ( STDIN ) ) ; } else { $ input = self :: getPassword ( false ) ; echo PHP_EOL ; } if ( $ input == '' ) $ input = $ default ; return $ input ; }
|
Asks the user for input
|
16,792
|
public function create ( $ model = null , $ options = [ ] ) { $ defaults = [ 'inputDefaults' => [ 'div' => [ 'class' => 'form-group' , ] , 'label' => [ 'class' => 'control-label' , ] , 'class' => 'form-control' , 'error' => [ 'attributes' => [ 'wrap' => 'p' , 'class' => 'text-danger' , ] , ] , ] , 'class' => null , 'role' => 'form' , ] ; $ options = Hash :: merge ( $ defaults , $ options ) ; return parent :: create ( $ model , $ options ) ; }
|
Starts a new form with input defaults .
|
16,793
|
public function btnReset ( $ title = '' , $ options = [ ] ) { $ title = empty ( $ title ) ? __ ( 'Reset' ) : $ title ; $ options = array_merge ( [ 'class' => 'btn btn-success' , 'type' => 'reset' , ] , $ options ) ; return parent :: button ( $ title , $ options ) ; }
|
Creates a reset button for a form
|
16,794
|
public function btnSubmit ( $ title = '' , $ options = [ ] ) { $ title = empty ( $ title ) ? __ ( 'Submit' ) : $ title ; $ options = array_merge ( [ 'class' => 'btn btn-success' , 'type' => 'submit' , ] , $ options ) ; return parent :: button ( $ title , $ options ) ; }
|
Creates a submit button for a form
|
16,795
|
public function btnCancel ( $ title = '' , $ options = [ ] ) { $ title = empty ( $ title ) ? __ ( 'Cancel' ) : $ title ; $ options = array_merge ( [ 'class' => 'btn btn-danger' , 'type' => 'reset' , 'data-dismiss' => 'modal' , ] , $ options ) ; return parent :: button ( $ title , $ options ) ; }
|
Creates a cancel button . Used to dismiss modals
|
16,796
|
public function end ( $ options = null , $ secureAttributes = [ ] ) { if ( ! empty ( $ options ) ) { if ( ! is_array ( $ options ) ) { $ options = [ 'label' => $ options ] ; } $ defaults = [ 'class' => 'btn btn-success' , ] ; $ options = array_merge ( $ defaults , $ options ) ; } return parent :: end ( $ options , $ secureAttributes ) ; }
|
Add divs and classes necessary for bootstrap to end form .
|
16,797
|
protected function handleCharacter47 ( ) { if ( $ this -> inQuotes || $ this -> inSingleQuotes || $ this -> inCondition ) return true ; return parent :: handleCharacter47 ( ) ; }
|
Handle javascript matches
|
16,798
|
protected function handleCharacter32 ( ) { $ this -> lastSpace = $ this -> currentIndex ; if ( ! empty ( $ this -> keywordHashMap [ $ this -> buildingWord ] ) ) { return true ; } if ( ( chr ( $ this -> nextCharacter ) . $ this -> input [ $ this -> currentIndex + 2 ] ) == 'in' ) { return true ; } if ( $ this -> inCondition ) { return true ; } if ( $ this -> inQuotes ) { return true ; } if ( $ this -> inSingleQuotes ) { return true ; } return false ; }
|
Handle un - quoted spaces
|
16,799
|
public function load ( Repo $ repo ) { $ scrutinizerRepo = $ this -> client -> fetchRepository ( new Repository ( $ repo -> getSlug ( ) , $ repo -> getType ( ) ) ) ; if ( $ scrutinizerRepo ) { $ repo -> setMetrics ( $ scrutinizerRepo -> getMetrics ( ) ) ; $ repo -> setPdependMetrics ( $ scrutinizerRepo -> getPdependMetrics ( ) ) ; } return $ repo ; }
|
Load scruinitzer infos for repository
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.