/** * Delete current HRJobContract based on array-data * * @param array $params key-value pairs * @return CRM_HRJob_DAO_HRJobContract|NULL * */ public function delete($useWhere = false) { $id = $this->id; $result = parent::delete($useWhere); if ($result !== false && module_exists('rules')) { rules_invoke_event('hrjobcontract_after_delete', $id); } }
/** * Executes particular action with the node.. */ public static function doAction($action_type, $nid) { switch ($action_type) { case ActionTypeEnum::NONE: // Do nothing. break; case ActionTypeEnum::RULES_EVENT: if (module_exists('rules')) { $node = node_load($nid); rules_invoke_event('node_expired', $node); } else { throw new ExpireException(t('Module Rules is not installed.')); } break; case ActionTypeEnum::NODE_PUBLISH: NodeHelper::publishNode($nid); break; case ActionTypeEnum::NODE_UNPUBLISH: NodeHelper::unpublishNode($nid); break; case ActionTypeEnum::NODE_STICKY: NodeHelper::makeNodeSticky($nid); break; case ActionTypeEnum::NODE_UNSTICKY: NodeHelper::makeNodeUnsticky($nid); break; case ActionTypeEnum::NODE_PROMOTE_TO_FRONT: NodeHelper::promoteNode($nid); break; case ActionTypeEnum::NODE_REMOVE_FROM_FRONT: NodeHelper::unpromoteNode($nid); break; default: // Do nothing. break; } }
/** * Notify other modules that a session imitation event has occured. * * When a session limit is reached, this hook is invoked. There are * two types of event. Collision events happen when a new session * causes an old session to close. Disconnect events happen when * a new session is prevented by an existing session. * * @param string $sid * The session id of the session which caused the event. In a * collision, this is not the session which was ended. * @param string $op * Either 'disconnect' or 'collision'. */ function hook_session_limit($sid, $op) { global $user; rules_invoke_event('session_limit_' . $op, $user, $sid); }
/** * Updates the local content of $target_code with data from a Lingotek Document * * @param string $lingotek_locale * The code for the language that needs to be updated. * @return bool * TRUE if the content updates succeeded, FALSE otherwise. */ public function downloadTriggered($lingotek_locale) { if (module_exists('rules')) { rules_invoke_event('lingotek_entity_translation_ready', new EntityDrupalWrapper($this->entity_type, $this->entity)); } return lingotek_entity_download_triggered($this->entity, $this->entity_type, $lingotek_locale); }
/** * Alters a line item on an order when the order is loaded. * * @param &$item * The line item array. * @param $order * The order object containing the line item. */ function hook_uc_line_item_alter(&$item, $order) { $account = user_load($order->uid); rules_invoke_event('calculate_line_item_discounts', $item, $account); }
/** * Checks to see if overall status has changed. * * If status has changed and the rules module is enabled, fires the * appropriate event. */ public function checkStatusChange() { if (empty($this->appId) || empty($this->orgName)) { return; } $new_status = self::getNumericStatus($this->overallStatus); $previous_status = db_select('dc_dev_app_previous_status', 'd')->fields('d', array('status'))->condition('app_id', $this->appId)->execute()->fetchField(); if ($previous_status === FALSE) { if (isset($new_status)) { db_insert('dc_dev_app_previous_status')->fields(array('app_id' => $this->appId, 'org_name' => $this->orgName, 'status' => $new_status))->execute(); } } elseif ($new_status != $previous_status) { db_update('dc_dev_app_previous_status')->fields(array('status' => $new_status))->condition('app_id', $this->appId)->execute(); if (module_exists('rules')) { $event = NULL; switch ($previous_status) { case -1: $event = 'revoked_'; break; case 0: $event = 'pending_'; break; case 1: $event = 'approved_'; break; } $event .= $this->overallStatus; if ($event && strlen($event) > 10) { rules_invoke_event('devconnect_developer_app_status_' . $event, $this); } } } }
/** * Called when various revision operations happen. * * @param string $op * one of: * 'pre publish' * 'post publish' * 'pre unpublish' * 'post unpublish' * 'post update' * 'pre delete' * 'post delete' * 'pre revert' * 'post revert' * * @param object $node_revision */ function hook_revisionapi($op, $node_revision) { if ($op == 'pre publish' && module_exists('rules')) { rules_invoke_event('revisioning_pre_publish', $node); } }
/** * Insert a commit, branch or tag operation into the database, and call the * necessary module hooks. Only call this function after the operation has been * successfully executed. * * @param $operation_items * A structured array containing the exact details of happened to each * item in this operation. The structure of this array is the same as * the return value of VersioncontrolOperation::getItems() - that is, * elements for 'type', 'path' and 'revision' - but doesn't include the * 'item_revision_id' element, that one will be filled in by this function. * * For commit operations, you also have to fill in the 'action' and * 'source_items' elements (and optionally 'replaced_item') that are also * described in the VersioncontrolOperation::getItems() API documentation. * The 'line_changes' element, as in VersioncontrolOperation::getItems(), * is optional to provide. * * This parameter is passed by reference as the insert operation will * check the validity of a few item properties and will also assign an * 'item_revision_id' property to each of the given items. So when this * function returns with a result other than NULL, the @p $operation_items * array will also be up to snuff for further processing. * * @return * The finalized operation array, with all of the 'vc_op_id', 'repository' * and 'uid' properties filled in, and 'repo_id' removed if it existed before. * Labels are now equipped with an additional 'label_id' property. * (For more info on these labels, see the API documentation for * versioncontrol_get_operations() and VersioncontrolOperation::getItems().) * In case of an error, NULL is returned instead of the operation array. */ public final function insert(&$operation_items) { $this->fill(TRUE); if (!isset($this->repository)) { return NULL; } // Ok, everything's there, insert the operation into the database. $this->repo_id = $this->repository->repo_id; // for drupal_write_record() //FIXME $this->uid = 0; drupal_write_record('versioncontrol_operations', $this); unset($this->repo_id); // drupal_write_record() has now added the 'vc_op_id' to the $operation array. // Insert labels that are attached to the operation. $this->setLabels($this->labels); $vcs = $this->repository->vcs; // So much for the operation itself, now the more verbose part: items. ksort($operation_items); // similar paths should be next to each other foreach ($operation_items as $path => $item) { $item->sanitize(); $item->ensure(); $this->insertOperationItem($item, VERSIONCONTROL_OPERATION_MEMBER_ITEM); $item['selected_label'] = new stdClass(); $item['selected_label']->get_from = 'operation'; $item['selected_label']->successor_item =& $this; // If we've got source items (which is the case for commit operations), // add them to the item revisions and source revisions tables as well. foreach ($item->source_items as $key => $source_item) { $source_item->ensure(); $item->insertSourceRevision($source_item, $item->action); // Cache other important items in the operations table for 'path' search // queries, because joining the source revisions table is too expensive. switch ($item['action']) { case VERSIONCONTROL_ACTION_MOVED: case VERSIONCONTROL_ACTION_COPIED: case VERSIONCONTROL_ACTION_MERGED: if ($item->path != $source_item->path) { $this->insertOperationItem($source_item, VERSIONCONTROL_OPERATION_CACHED_AFFECTED_ITEM); } break; default: // No additional caching for added, modified or deleted items. break; } $source_item->selected_label = new stdClass(); $source_item->selected_label->get_from = 'other_item'; $source_item->selected_label->other_item =& $item; $source_item->selected_label->other_item_tags = array('successor_item'); $item->source_items[$key] = $source_item; } // Plus a special case for the "added" action, as it needs an entry in the // source items table but contains no items in the 'source_items' property. if ($item->action == VERSIONCONTROL_ACTION_ADDED) { $item->insertSourceRevision(0, $item['action']); } // If we've got a replaced item (might happen for copy/move commits), // add it to the item revisions and source revisions table as well. if (isset($item->replaced_item)) { $item->replaced_item->ensure(); $item->insertSourceRevision($item->replaced_item, VERSIONCONTROL_ACTION_REPLACED); $item->replaced_item->selected_label = new stdClass(); $item->replaced_item->selected_label->get_from = 'other_item'; $item->replaced_item->selected_label->other_item =& $item; $item->replaced_item->selected_label->other_item_tags = array('successor_item'); } $operation_items[$path] = $item; } // Notify the backend first. $this->_insert($operation_items); // Everything's done, let the world know about it! module_invoke_all('versioncontrol_operation', 'insert', $this, $operation_items); // This one too, as there is also an update function & hook for it. // Pretend that the labels didn't exist beforehand. $labels = $this->labels; $this->labels = array(); module_invoke_all('versioncontrol_operation_labels', 'insert', $this, $labels); $this->labels = $labels; // Rules integration, because we like to enable people to be flexible. // FIXME change callback if (module_exists('rules')) { rules_invoke_event('versioncontrol_operation_insert', array('operation' => $this, 'items' => $operation_items)); } //FIXME avoid return, it's on the object return $this; }
public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) { // If Rules is available, signal the reversion. // @todo: move this Rules_invoke_event to hook outside this module. if (\Drupal::moduleHandler()->moduleExists('rules')) { rules_invoke_event('workflow_state_reverted', $this->entity); } /* @var $transition WorkflowTransitionInterface */ $transition = $this->prepareRevertedTransition($this->entity); // The entity will be updated when the transition is executed. Keep the // original one for the confirmation message. $previous_sid = $transition->getToSid(); // Force the transition because it's probably not valid. $transition->force(TRUE); $new_sid = workflow_execute_transition($transition, TRUE); $comment = $previous_sid == $new_sid ? 'State is reverted.' : 'State could not be reverted.'; drupal_set_message(t($comment), 'warning'); $form_state->setRedirect('entity.node.workflow_history', array('node' => $transition->getTargetEntityId(), 'field_name' => $transition->getFieldName())); }
public static function create($params) { $className = get_called_class(); $entityName = _civicrm_get_entity_name($className); $baoName = 'CRM_Hrjobcontract_BAO_' . $entityName; $daoName = 'CRM_Hrjobcontract_DAO_' . $entityName; $tableName = _civicrm_get_table_name($className); $hook = empty($params['id']) ? 'create' : 'edit'; if ($hook === 'create') { if (empty($params['jobcontract_id'])) { throw new API_Exception("Cannot create entity: please specify jobcontract_id value."); } $jobContractId = (int) $params['jobcontract_id']; $previousEntityParams = array('jobcontract_id' => $jobContractId, 'sequential' => 1); _civicrm_hrjobcontract_api3_set_current_revision($previousEntityParams, $tableName); $previousEntityResult = civicrm_api3($entityName, 'get', $previousEntityParams); $previousEntity = CRM_Utils_Array::first($previousEntityResult['values']); if (!empty($previousEntity)) { $classInstance = new $daoName(); $previousInstance = $classInstance->create($previousEntity); /*$previousInstance = new $baoName(); if (!empty($previousEntity)) { $previousInstance->id = $previousEntity['id']; $previousInstance->find(true); }*/ } if (empty($params['jobcontract_revision_id'])) { // Creating new revision: $newRevision = _civicrm_hrjobcontract_api3_create_revision($jobContractId); $params['jobcontract_revision_id'] = $newRevision['id']; // Updating currently saved revision with its 'id' as {table}_revision_id: $updatedRevision = civicrm_api3('HRJobContractRevision', 'create', array('sequential' => 1, 'id' => $newRevision['id'], $tableName . '_revision_id' => $newRevision['id'])); } else { $updatedRevision = civicrm_api3('HRJobContractRevision', 'create', array('sequential' => 1, 'id' => $params['jobcontract_revision_id'], $tableName . '_revision_id' => $params['jobcontract_revision_id'])); } if (!empty($previousEntity)) { unset($previousEntity['id']); unset($previousEntity['jobcontract_revision_id']); $previousEntityData = array(); foreach ($previousEntity as $key => $value) { $previousEntityData[$key] = $previousInstance->{$key}; } $params = array_merge($previousEntityData, $params); } } foreach ($params as $key => $value) { if (is_array($value)) { $params[$key] = json_encode($value); } } CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); $instance = new $className(); if (!empty($params['id'])) { $instance->id = $params['id']; $instance->find(true); } $instance->copyValues($params); if (module_exists('rules')) { rules_invoke_event('hrjobcontract_' . $tableName . '_presave', $instance); } $instance->save(); CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); if (module_exists('rules')) { if ($hook == 'create') { rules_invoke_event('hrjobcontract_' . $tableName . '_insert', $instance); } else { rules_invoke_event('hrjobcontract_' . $tableName . '_update', $instance); } } return $instance; }
/** * Alters a line item on an order when the order is loaded. * * @param &$item * The line item array. * @param $order * The order object containing the line item. */ function hook_uc_line_item_alter(&$item, $order) { rules_invoke_event('calculate_line_item_discounts', $item, $order->getOwner()); }