Beispiel #1
0
 /**
  * Returns the stripped down form on a workflow
  *
  * @param object com_meego_package_details object
  */
 public function get_stripped_forms_for_package($package = null)
 {
     $retval = array();
     $object = new com_meego_package($package->packageguid);
     $workflows = midgardmvc_helper_workflow_utils::get_workflows_for_object($object);
     if (is_array($workflows)) {
         $this->mvc->component->load_library('Workflow');
         foreach ($workflows as $name => $workflow_data) {
             $args = array('package' => $package->packagename, 'version' => $package->packageversion, 'project' => $package->repoprojectname, 'repository' => $package->reponame, 'arch' => $package->repoarch, 'workflow' => $name);
             $workflow_definition = new $workflow_data['provider']();
             $values = $workflow_definition->start($object);
             $workflow = $workflow_definition->get();
             if (isset($values['review_form'])) {
                 $form = new midgardmvc_ui_forms_form($values['review_form']);
                 $fields = midgardmvc_ui_forms_generator::list_fields($form);
                 foreach ($fields as $field) {
                     $retval[$name][$field->title]['widget'] = $field->widget;
                     $retval[$name][$field->title]['options'] = $field->options;
                 }
             } else {
                 if (isset($values['execution'])) {
                     $args['execution'] = $values['execution'];
                     $execution = new midgardmvc_helper_workflow_execution_interactive($workflow, $args['execution']);
                     $variables = $execution->getVariables();
                     if (isset($variables['review_form'])) {
                         $form = new midgardmvc_ui_forms_form($variables['review_form']);
                         $fields = midgardmvc_ui_forms_generator::list_fields($form);
                         foreach ($fields as $field) {
                             $retval[$name][$field->title]['widget'] = $field->widget;
                             $retval[$name][$field->title]['options'] = $field->options;
                         }
                     }
                 }
             }
         }
     }
     return $retval;
 }
Beispiel #2
0
 /**
  * Process a comment post
  */
 public function post_add(array $args)
 {
     $success = true;
     if (!$this->user) {
         // Voting requires authentication
         $auth = com_meego_ocs_utils::authenticate($args);
         if (!$auth) {
             return null;
         }
     }
     $ocs = new com_meego_ocs_OCSWriter();
     if (!isset($_POST['content'])) {
         $ocs->writeError('Content must not be empty', 101);
         $ocs->endDocument();
         self::output_xml($ocs);
         return;
     }
     if (!(isset($_POST['message']) || isset($_POST['subject']))) {
         $ocs->writeError('Message or subject must not be empty', 102);
         $ocs->endDocument();
         self::output_xml($ocs);
         return;
     }
     if ($_POST['type'] != '1' && $_POST['type'] != '8') {
         $ocs->writeError('Content type: ' . $_POST['type'] . ' is not supported.', 104);
         $ocs->endDocument();
         self::output_xml($ocs);
         return;
     }
     $package = new com_meego_package();
     $package->get_by_id((int) $_POST['content']);
     if (!$package->guid) {
         $success = false;
         $this->mvc->log(__CLASS__, 'Package with id: ' . $_POST['content'] . ' not found.', 'error');
     }
     if ($success) {
         switch ($_POST['type']) {
             case 1:
                 $message = 'Rating via OCS failed. Could not create rating object for package ' . $package->name . '(id: ' . $package->id . ').';
                 $comment = new com_meego_comments_comment();
                 if (isset($_POST['parent']) && !empty($_POST['parent'])) {
                     $parent = new com_meego_comments_comment();
                     $parent->get_by_id((int) $_POST['parent']);
                     if ($parent->to != $package->guid) {
                         $success = false;
                         $this->mvc->log(__CLASS__, $message . ' Parent comment is not related to the content item', 'error');
                     }
                     $comment->up = $parent->id;
                 }
                 $comment->to = $package->guid;
                 $comment->content = $_POST['message'];
                 if (isset($_POST['subject']) && !empty($_POST['subject'])) {
                     $comment->title = $_POST['subject'];
                 }
                 $comment->create();
                 if ($comment->guid) {
                     $rating = new com_meego_ratings_rating();
                     $rating->to = $package->guid;
                     // for comments we have no votes
                     $rating->rating = 0;
                     $rating->comment = $comment->id;
                     $success = $rating->create();
                     if ($success) {
                         $message = 'Rating via OCS finished. New rating object is: ' . $rating->guid . '.';
                     }
                 }
                 break;
             case 8:
                 $name = substr($_POST['message'], 0, strpos($_POST['message'], ':'));
                 $workflows = $this->mvc->configuration->workflows;
                 if (array_key_exists($name, $workflows)) {
                     if (is_object($package)) {
                         $this->mvc->component->load_library('Workflow');
                         $workflow_definition = new $workflows[$name]['provider']();
                         $values = $workflow_definition->start($package);
                         if (array_key_exists('execution', $values)) {
                             // get the db form and fill in the fields
                             $form = new midgardmvc_ui_forms_form($values['review_form']);
                             $transaction = new midgard_transaction();
                             $transaction->begin();
                             $instance = new midgardmvc_ui_forms_form_instance();
                             $instance->form = $form->id;
                             $instance->relatedobject = $package->guid;
                             $instance->create();
                             if (isset($instance->guid)) {
                                 // give values to the db fields taken from the posted values and store each of them
                                 // use the form instance ID as "form" property of the fields
                                 $posted_values = explode(',', substr($_POST['message'], strpos($_POST['message'], ':') + 1));
                                 $db_fields = midgardmvc_ui_forms_generator::list_fields($form);
                                 $i = 0;
                                 foreach ($db_fields as $dbfield) {
                                     if (!$success) {
                                         // if 1 field creation failed then end this loop as fast as possible
                                         continue;
                                     }
                                     switch ($dbfield->widget) {
                                         case 'checkbox':
                                             $holder = "booleanvalue";
                                             $value = $posted_values[$i];
                                             break;
                                         default:
                                             $options = explode(',', $dbfield->options);
                                             $value = $options[(int) $posted_values[$i]];
                                             $holder = "stringvalue";
                                     }
                                     $field_instance = new midgardmvc_ui_forms_form_instance_field();
                                     $field_instance->form = $instance->id;
                                     $field_instance->field = $dbfield->guid;
                                     $field_instance->{$holder} = $value;
                                     if (!$field_instance->create()) {
                                         $success = false;
                                     }
                                     ++$i;
                                 }
                                 if ($success) {
                                     $message = 'QA via OCS by user ' . $this->user->login . ' for package: ' . $package->name . ' (id: ' . $package->id . ')';
                                     try {
                                         $workflow = $workflow_definition->get();
                                         $execution = new midgardmvc_helper_workflow_execution_interactive($workflow, $values['execution']);
                                     } catch (ezcWorkflowExecutionException $e) {
                                         $success = false;
                                         $this->mvc->log(__CLASS__, $message . ' failed. Workflow: ' . $values['workflow'] . ' not found. See error: ' . $e->getMessage(), 'error');
                                     }
                                     if ($success) {
                                         $args = array('review' => $instance->guid);
                                         try {
                                             $values = $workflow_definition->resume($execution->guid, $args);
                                         } catch (ezcWorkflowInvalidInputException $e) {
                                             $success = false;
                                             $this->mvc->log(__CLASS__, $message . ' failed. Maybe a quick re-submit? See error: ' . $e->getMessage(), 'error');
                                         }
                                         $transaction->commit();
                                         $this->mvc->log(__CLASS__, 'New QA form guid: ' . $instance->guid, 'info');
                                     }
                                 }
                             }
                             if (!$success) {
                                 $this->mvc->log(__CLASS__, $message . ' failed. Probably a form instance or a field creation failed.', 'info');
                                 $transaction->rollback();
                             }
                         }
                     }
                 }
                 break;
         }
         if ($success) {
             // POST went fine
             $ocs->writeMeta(null, null, 'Posting succeded.', 'ok', 100);
             $this->mvc->log(__CLASS__, $message, 'info');
             // create activity object
             $created = null;
             switch ($_POST['type']) {
                 case 1:
                     $verb = 'comment';
                     $summary = 'The user commented an application via OCS.';
                     $creator = $rating->metadata->creator;
                     $created = $rating->metadata->created;
                     $target = $rating->to;
                     break;
                 case 8:
                     $verb = 'review';
                     $summary = 'The user reviewed an application via OCS.';
                     $creator = $instance->metadata->creator;
                     $created = $instance->metadata->created;
                     $target = $instance->relatedobject;
                     break;
             }
             if ($created) {
                 $res = midgardmvc_account_controllers_activity::create_activity($creator, $verb, $target, $summary, 'Apps', $created);
             }
             unset($created, $creator, $target);
         }
     }
     if (!$success) {
         $ocs->writeError('Comment posting (type: ' . $_POST['type'] . ') failed.');
         $this->mvc->log(__CLASS__, $message . ' failed.', 'info');
     }
     $ocs->endDocument();
     self::output_xml($ocs);
 }