Example #1
0
 /**
  * Kills all selected ScheduledTasks.
  * 
  * @param array|null $not_killed
  *   // a reference to an array that will be filled with any process_ids that
  *   // could not be killed for any reason.
  * 
  * @return void
  */
 public function stop($not_killed = null)
 {
     if (!is_null($not_killed)) {
         \Altumo\Validation\Arrays::assertArray($not_killed, '$not_killed expects null or array');
     }
     // get all frequent cron tasks running as this user and from the plugin's path
     $task_processes = $this->getSelectedProcesses();
     foreach ($task_processes as $task_process) {
         // skip if process doesn't have a process_id
         if (!array_key_exists('process_id', $task_process) || !strlen($task_process['process_id'])) {
             continue;
         }
         $result = \Altumo\Utils\SystemProcess::killProcess($task_process['process_id']);
         if (!is_null($not_killed)) {
             $not_killed[] = $result;
         }
     }
     $this->clearSelectedProcesses();
 }
Example #2
0
 /**
  * Returns true if:
  * 
  * - This is a PUT request
  * - The "ids" parameter contains at least one integer (can be a csv list)
  * - The decoded body is not an array of arrays
  * 
  * Expansion is required when a PUT request is made to apply the same changes to
  * an array of objects specified by the "ids" parameter.
  *
  */
 protected function messageBodyRequiresExpansion()
 {
     $method = $this->getMethod();
     try {
         $object_ids = \Altumo\Validation\Arrays::sanitizeCsvArrayPostitiveInteger($this->getParameter('ids', ''));
     } catch (\Exception $e) {
         $id_field_map = new \sfAltumoPlugin\Api\ApiFieldMap('id', null, 'ID');
         $response = \sfContext::getInstance()->getResponse();
         $response->addError('The primary key of the object you\'re trying to update was not set or was not a comma-separated list of integers.', null, $id_field_map);
         throw $e;
     }
     $raw_message_body = $this->getMessageBodyData();
     if ($method == self::PUT && !empty($object_ids)) {
         // If the body is not an array of arrays, we require expansion
         if (!isset($raw_message_body[0]) || !is_array($raw_message_body[0])) {
             return true;
         }
     }
     return false;
 }
 /**
  * Runs the write operation and sets the response body.
  * 
  * ApiResponseBody within the ApiResponse.
  * 
  */
 public function run()
 {
     $delete_object = $this->getDeleteObject();
     //function
     $query = $this->getQuery();
     $request = $this->getRequest();
     // Validate IDs
     try {
         $delete_object_ids = \Altumo\Validation\Arrays::sanitizeCsvArrayPostitiveInteger($request->getParameter('ids', ''));
     } catch (Exception $e) {
         throw new \Exception("One of the ids provided was invalid.");
     }
     if (empty($delete_object_ids)) {
         throw new \Exception("No valid ids were provided for deletion.");
     }
     // Get objects based on $query and filtering by ids
     $query->filterById($delete_object_ids);
     $objects_to_delete = $query->find();
     if ($objects_to_delete->isEmpty()) {
         throw new \Exception("No valid ids were provided for deletion.");
     }
     // Delete objects
     $deleted_ids = array();
     foreach ($objects_to_delete as $object_to_delete) {
         $deleted_ids[] = $object_to_delete->getId();
         $delete_object($object_to_delete);
     }
     $api_response_body = $this->getResponse()->getResponseBody();
     $api_response_body->setBody(array("deleted" => $deleted_ids));
 }
Example #4
0
 /**
  * Sorts an array of rows by scalar row values, maintain indexes
  *
  * @param array $rows
  *
  * @throws \Exception if uasort fails
  *
  * @return array
  */
 public static function sortArrayRowsAlphabetically($rows)
 {
     \Altumo\Validation\Arrays::assertArray($rows);
     $result_ok = uasort($rows, '\\Altumo\\Arrays\\Arrays::compareArrayRowsAlphabetically');
     if (!$result_ok) {
         throw new \Exception('Error sorting rows alphabetically');
     }
     return $rows;
 }
Example #5
0
 /**
  * Optionally builds a string to add to the end of the URL.
  *   eg.
  *       /2,4,5,6,8
  *
  * @param array $ids
  * @throws \Exception                    //if $ids is not null or an
  *                                         array of positive integers.
  * @return string
  */
 protected static function constructIdsUrlSuffix($ids = null)
 {
     $url_suffix = '';
     if (!is_null($ids)) {
         $ids = \Altumo\Validation\Arrays::sanitizeCsvArrayPostitiveInteger($ids);
         return '/' . implode(',', $ids);
     }
     return '';
 }
Example #6
0
 /**
  * API Action for api users to crud event subscriptions
  * 
  * @param ApiRequest $request
  * 
  * @return void
  */
 public function executeSystemEventSubscription(\sfAltumoPlugin\Api\ApiRequest $request)
 {
     try {
         /* @var $response \sfAltumoPlugin\Api\ApiResponse() */
         $response = $this->getResponse();
         $user = $this->assertAndRetrieveAuthenticatedUser($request);
         //prepare the query
         $query = SystemEventSubscriptionQuery::create()->joinSystemEvent();
         // if ids set, filter for those
         $ids_filter_value = $request->getParameter('ids');
         if (!empty($ids_filter_value)) {
             $query->filterById(\Altumo\Validation\Arrays::sanitizeCsvArrayPostitiveInteger($ids_filter_value));
         }
         //do before_save checks
         $before_save = function (&$model, &$request_object, &$response, $remote_id, $update) {
             if (!$model->getUser()) {
                 $current_user = sfContext::getInstance()->getUser()->getUser();
                 $model->setUser($current_user);
             }
         };
         $plural = 'system_event_subscriptions';
         switch ($request->getMethod()) {
             case sfWebRequest::GET:
                 // select
                 $response->setStatusCode('200');
                 $api_get_query = new \sfAltumoPlugin\Api\ApiGetQuery($request, $response, $query, $plural, $this->getSystemEventSubscriptionResultModifier());
                 $api_get_query->runQuery();
                 break;
             case sfWebRequest::POST:
                 // insert
                 $response->setStatusCode('200');
                 $api_write_operation = new \sfAltumoPlugin\Api\ApiWriteOperation($request, $response, $plural);
                 $api_write_operation->setFieldMaps($this->getSystemEventSubscriptionFieldMappings());
                 $api_write_operation->setUpdate(false);
                 $api_write_operation->setQuery($query);
                 $api_write_operation->setModifyResult($this->getSystemEventSubscriptionResultModifier());
                 $api_write_operation->setBeforeSave($before_save);
                 $api_write_operation->run();
                 break;
             case sfWebRequest::PUT:
                 // update
                 $response->setStatusCode('200');
                 $api_write_operation = new \sfAltumoPlugin\Api\ApiWriteOperation($request, $response, $plural);
                 $api_write_operation->setFieldMaps($this->getSystemEventSubscriptionFieldMappings());
                 $api_write_operation->setUpdate(true);
                 $api_write_operation->setQuery($query);
                 $api_write_operation->setBeforeSave($before_save);
                 $api_write_operation->setModifyResult($this->getSystemEventSubscriptionResultModifier());
                 $api_write_operation->run();
                 break;
             case sfWebRequest::DELETE:
                 // delete
                 $response->setStatusCode('200');
                 $api_delete_operation = new \sfAltumoPlugin\Api\ApiDeleteOperation($request, $response, $query);
                 $api_delete_operation->run();
                 break;
             default:
                 // action not supported
                 $response->setStatusCode('405');
                 break;
         }
     } catch (Exception $e) {
         $response->addException($e);
     }
     return $response->respond();
 }