Ejemplo n.º 1
0
 /**
  * Process an attribute setting POST
  * args['context'] might be: installed
  * args['key'] holds the package ID
  * @param args see above
  */
 public function post_setattribute(array $args)
 {
     $summary = '';
     $success = true;
     if (!$this->user) {
         // this operation requires authentication
         $auth = com_meego_ocs_utils::authenticate($args);
         if (!$auth) {
             com_meego_ocs_utils::end_with_error('This interface is available for authenticated users only', 199);
         }
     }
     if (!isset($args['context'])) {
         com_meego_ocs_utils::end_with_error('Mandatory context missing (e.g. installed)', 102);
     }
     if (!isset($args['key'])) {
         com_meego_ocs_utils::end_with_error('Mandatory package ID missing', 103);
     }
     // check if the context is supported
     switch ($args['context']) {
         case 'save':
             $summary = 'User succesfully installed an application.';
             break;
         case 'unsave':
             $summary = 'User succesfully uninstalled an application.';
             break;
         case 'savefail':
             $summary = 'Application installation failed.';
             break;
         default:
             com_meego_ocs_utils::end_with_error('This context: ' . $args['context'] . ' is not supported', 104);
     }
     $package = new com_meego_package();
     try {
         $package->get_by_id((int) $args['key']);
     } catch (Exception $e) {
         $success = false;
         com_meego_ocs_utils::end_with_error('Package with id: ' . $args['key'] . ' not found', 105);
     }
     if ($success) {
         $res = midgardmvc_account_controllers_activity::create_activity($this->user->person, $args['context'], $package->guid, $summary, 'Apps');
         if (!$res) {
             com_meego_ocs_utils::end_with_error('Failed to create activity object.', 106);
         }
     }
     // everything went fine
     $ocs = new com_meego_ocs_OCSWriter();
     $ocs->writeMeta(null, null, 'Attribute setting succeded.', 'ok', 100);
     $ocs->endDocument();
     com_meego_ocs_utils::output_xml($ocs);
 }
Ejemplo n.º 2
0
 /**
  * @todo: docs
  */
 public function execute(ezcWorkflowExecution $execution)
 {
     $form = midgardmvc_ui_forms_generator::get_by_guid($execution->getVariable('review_form'));
     $instance = new midgardmvc_ui_forms_form_instance($execution->getVariable('review'));
     $review = midgardmvc_ui_forms_store::load_form($form, $instance);
     $items = $form->items;
     $boolean_count = 0;
     $positive = 0;
     $package = new com_meego_package($instance->relatedobject);
     foreach ($items as $key => $item) {
         if ($key == "redirect_link" || $key == "execution") {
             continue;
         }
         try {
             $field = new midgardmvc_ui_forms_form_field($key);
         } catch (Exception $e) {
             midgardmvc_core::get_instance()->log('Invalid field detected in distill review: ' . $key . ', value: ' . $item, 'warning');
         }
         // todo: ugly hardcoded check, but what can we do..
         if ($field->title == "Should the application be in this application catalog?") {
             // if the answer belongs to a certain field then we process
             // this field must be a boolean too
             if ($item instanceof midgardmvc_helper_forms_field_boolean) {
                 if ($item->get_value()) {
                     // add +1 to the package score
                     $package->metadata->score++;
                 } else {
                     //  oh yes, we do give -1 points too ;)
                     $package->metadata->score--;
                 }
                 $res = $package->update();
                 if (!$res) {
                     //update failed; do what?
                 }
             }
         } else {
             // otherwise
             continue;
         }
     }
     // pass on the score
     $execution->setVariable('distilled_review', $package->metadata->score);
 }
Ejemplo n.º 3
0
 /**
  * Sets data for the template
  * It is used in two routes so that is why we have it as a separate function
  * @param array of packages
  */
 public function set_data(array $packages)
 {
     // let's do a smart grouping by package_title (ie. short names)
     $variant_counter = 0;
     foreach ($packages as $package) {
         $this->data['categorytree'] = self::determine_category_tree($package);
         $tree_url = $this->mvc->dispatcher->generate_url('package_overview_tree', array('categorytree' => $this->data['categorytree'], 'packagename' => $package->packagename), $this->request);
         // certain things must not be recorded in evert iteration of this loop
         // if we recorded the name, then we are pretty sure we recorded everything
         if (!isset($this->data['packages'][$package->packagename]['name'])) {
             // set the name
             $this->data['packages'][$package->packagename]['name'] = $package->packagename;
             if (isset($this->data['base']) && $this->data['base']) {
                 // if browsing by base categories, then we have to figure out the
                 // the category tree of the package
                 //$this->data['categorytree'] = self::determine_category_tree($package);
                 if (!strlen($this->data['basecategory'])) {
                     $this->data['basecategory'] = self::determine_base_category($package);
                 }
                 // if base category is still empty
                 // then it means that this package is not yet covered by any base category
                 // so we have to provide a different URL
                 if (!strlen($this->data['basecategory'])) {
                     // local url to a package index page
                     $this->data['packages'][$package->packagename]['localurl'] = $tree_url;
                 } else {
                     // ok, so we got a base category, let's form the url
                     // check if we have ux
                     if (!array_key_exists('ux', $this->data)) {
                         if ($package->repoosux == '') {
                             $this->data['ux'] = 'universal';
                         } else {
                             $this->data['ux'] = strtolower($package->repoosux);
                         }
                     }
                     // if could not figure out the ux then provide a tree url
                     if (!strlen($this->data['ux'])) {
                         $this->data['packages'][$package->packagename]['localurl'] = $tree_url;
                     } else {
                         $this->data['packages'][$package->packagename]['localurl'] = $this->mvc->dispatcher->generate_url('apps_by_name', array('os' => $package->repoos, 'version' => $package->repoosversion, 'ux' => $this->data['ux'], 'basecategory' => $this->data['basecategory'], 'packagename' => $package->packagename), $this->request);
                     }
                     $this->data['ux'] = '';
                     $this->data['basecategory'] = '';
                 }
             } else {
                 // local url to a package index page
                 $this->data['packages'][$package->packagename]['localurl'] = $tree_url;
             }
             // gather some basic stats
             $stats = self::get_statistics($package->packagename);
             // set the total number of comments
             $this->data['packages'][$package->packagename]['number_of_comments'] = $stats['number_of_comments'];
             // the stars as html snippet for the average rating; should be used as-is in the template
             $this->data['packages'][$package->packagename]['stars'] = com_meego_ratings_controllers_rating::draw_stars($stats['average_rating']);
             // set a longer description
             $this->data['packages'][$package->packagename]['description'] = $package->packagedescription;
             // set a screenshoturl if the package object has any
             $this->data['packages'][$package->packagename]['screenshoturl'] = false;
             $_package = new com_meego_package($package->packageid);
             $attachments = $_package->list_attachments();
             foreach ($attachments as $attachment) {
                 if ($attachment->mimetype == 'image/png' && !$this->data['packages'][$package->packagename]['screenshoturl']) {
                     $this->data['packages'][$package->packagename]['screenshoturl'] = $this->mvc->dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => 'prop480x300', 'filename' => $attachment->name), '/');
                     break;
                 }
             }
         }
         // we group the variants into providers. a provider is basically a project repository, e.g. home:fal
         $this->data['packages'][$package->packagename]['providers'][$package->repoprojectname]['projectname'] = $package->repoprojectname;
         // if the UX is empty then we consider the package to be good for all UXes
         // this value is used in the template to show a proper icon
         $package->ux = $package->repoosux;
         if (!strlen($package->ux)) {
             $package->ux = 'universal';
         }
         // provide a link to visit the page of a certain package variant
         /*
                     $package->localurl = $this->mvc->dispatcher->generate_url
                     (
                         'package_instance',
                         array
                         (
                             'package' => $package->packagename,
                             'version' => $package->packageversion,
                             'project' => $package->repoprojectname,
                             'repository' => $package->reponame,
                             'arch' => $package->repoarch
                         ),
                         $this->request
                     );
         */
         $basecategory = null;
         if (is_numeric($package->basecategory)) {
             $basecategory = self::determine_base_category($package);
         } else {
             $basecategory = $package->basecategory;
         }
         if ($basecategory) {
             $package->localurl = $this->mvc->dispatcher->generate_url('apps_by_name', array('os' => $package->repoos, 'version' => $package->repoosversion, 'ux' => $package->ux, 'basecategory' => $basecategory, 'packagename' => $package->packagename), $this->request);
         }
         // the variants are basically the versions built for different hardware architectures (not UXes)
         $this->data['packages'][$package->packagename]['providers'][$package->repoprojectname]['variants'][] = $package;
     }
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
 /**
  * Sets $this->data['packages'] for the template
  *
  * This function groups packages into applications, so e.g. 5 variants of
  * the same package will mean 1 item in the final array.
  *
  * @param array of com_meeg_package_details objects
  * @param string filter type: 'top' or 'staging': settings URL will depend on it
  * @param boolean if true then return info about older packages too
  *
  * @return array
  *
  */
 public function set_data(array $packages, $filter_type = 'top', $history = false)
 {
     $all = array();
     // a flag for tricky situations caused by additional hand imports
     $remember = false;
     // store guid for promoted apps (ie. apps that passed qa)
     $promotedtoguid = '';
     $promotedfromguid = '';
     $default_latest = array('packagescore' => '', 'packagename' => '', 'packageguid' => '', 'promotedfromguid' => '', 'promotedtoguid' => '', 'os' => '', 'version' => '', 'size' => 'n/a', 'promoted' => 'n/a', 'released' => 'n/a', 'lastupdate' => 'n/a', 'variants' => array(), 'iconurl' => '');
     $latest = $default_latest;
     $matched = $this->request->get_route()->get_matched();
     // this index will be used to grab the download URL of the appropriate arch variant of the package
     $index = 0;
     // this method is called from other classes too
     $this->isuser = $this->mvc->authentication->is_user();
     if (isset($matched['ux']) && array_key_exists($matched['ux'], $this->mvc->configuration->ux_arch_map)) {
         $index = $this->mvc->configuration->ux_arch_map[$matched['ux']];
     }
     foreach ($packages as $package) {
         if ($package->packagename != $latest['packagename']) {
             // processing a different package, so reset some internal arrays
             $all = array();
             $latest = $default_latest;
         }
         if (!isset($this->data['packages'][$package->packagename]['name'])) {
             // set the guid
             $this->data['packages'][$package->packagename]['packageguid'] = $package->packageguid;
             // set the name
             $this->data['packages'][$package->packagename]['name'] = $package->packagename;
             // set the title
             $this->data['packages'][$package->packagename]['title'] = $package->packagetitle;
             // get roles
             $this->data['packages'][$package->packagename]['roles'] = self::get_roles($package->packageguid);
             // gather some basic stats
             $stats = com_meego_packages_controllers_package::get_statistics($package->packagename);
             // set the total number of comments
             $this->data['packages'][$package->packagename]['number_of_comments'] = $stats['number_of_comments'];
             // figure out if there are posted forms for this app
             $this->data['packages'][$package->packagename]['posted_forms'] = count(com_meego_packages_forms::get_all_forms($package->packageguid));
             if (array_key_exists('number_of_rates', $stats)) {
                 // total number of rates
                 $this->data['packages'][$package->packagename]['number_of_rates'] = $stats['number_of_rates'];
             }
             // the stars as html snippet for the average rating; should be used as-is in the template
             $this->data['packages'][$package->packagename]['average_rating'] = $stats['average_rating'];
             $this->data['packages'][$package->packagename]['stars'] = com_meego_ratings_controllers_rating::draw_stars($stats['average_rating']);
             // collect ratings and comments (used in application detailed view)
             if (!array_key_exists('ratings', $this->data['packages'][$package->packagename])) {
                 $this->data['packages'][$package->packagename]['ratings'] = array();
             }
             $ratings = self::prepare_ratings($package->packagename, $history);
             $this->data['packages'][$package->packagename]['ratings'] = $ratings['ratings'];
             $this->data['packages'][$package->packagename]['is_there_comment'] = $history ? $history : $ratings['comment'];
             // set a summary
             $this->data['packages'][$package->packagename]['summary'] = $package->packagesummary;
             // set a longer description
             $this->data['packages'][$package->packagename]['description'] = $package->packagedescription;
             $this->data['packages'][$package->packagename]['basecategoryname'] = $package->basecategoryname;
             // base category name
             $this->data['packages'][$package->packagename]['iconurl'] = false;
             $this->data['packages'][$package->packagename]['screenshoturl'] = false;
             // a package may have multiple arches
             // but we should nominate one to be the default in order to support the new design
             $this->data['packages'][$package->packagename]['defaultdownloadurl'] = false;
             $_package = new com_meego_package($package->packageid);
             $attachments = $_package->list_attachments();
             $_icon_marker = 'icon.png';
             $_screenshot_marker = 'screenshot.png';
             $this->data['packages'][$package->packagename]['screenshots'] = false;
             foreach ($attachments as $attachment) {
                 if ($attachment->mimetype == 'image/png') {
                     if (strrpos($attachment->name, $_screenshot_marker) !== false) {
                         $this->data['packages'][$package->packagename]['screenshots'][] = $this->mvc->dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => 'prop480x300', 'filename' => $attachment->name), '/');
                     }
                     if (strrpos($attachment->name, $_icon_marker) !== false && !$this->data['packages'][$package->packagename]['iconurl']) {
                         $this->data['packages'][$package->packagename]['iconurl'] = $this->mvc->dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => 'icon', 'filename' => $attachment->name), '/');
                     }
                 }
             }
         }
         if (count($this->data['packages'][$package->packagename]['screenshots'])) {
             $this->data['packages'][$package->packagename]['screenshoturl'] = $this->data['packages'][$package->packagename]['screenshots'][0];
         }
         // if the UX is empty then we consider the package to be good for all UXes
         // this value is used in the template to show a proper icon
         $package->ux = $package->repoosux;
         if (!strlen($package->ux)) {
             $package->ux = 'universal';
         }
         $this->data['ux'] = $package->ux;
         // provide a link to visit the app page
         $package->localurl = self::get_localurl($package);
         // provide a link to visit the app's full history
         $this->data['packages'][$package->packagename]['historyurl'] = self::get_historyurl($package);
         $variant_info = array('ux' => $package->repoosux, 'repoos' => $package->repoos, 'repoarch' => $package->repoarch, 'packageid' => $package->packageid, 'packageguid' => $package->packageguid, 'packageinstallfileurl' => $package->packageinstallfileurl);
         //echo "current latest: " . $latest['packagename'] . ':' . $latest['version'] . ' vs package: ' . $package->packagename . ':' . $package->packageversion . "\n";
         if ($latest['version'] <= $package->packageversion) {
             $qarelease = $this->mvc->i18n->get('label_app_type_qarelease');
             $promoted = $this->mvc->i18n->get('label_app_type_promoted');
             $staging = $this->mvc->i18n->get('label_app_type_staging');
             //echo $package->packagename . ':' . $package->packageversion . ' from ' . $package->repoprojectname . " will be set as latest\n";
             //echo "latest score: " . $latest['packagescore'] . ', curtent package score: ' . $package->packagescore . "\n";
             if ($latest['packageguid']) {
                 if ($latest['version'] == $package->packageversion) {
                     if ($latest['repoid'] == $package->repoid && (int) $latest['packagescore'] > $package->packagescore) {
                         $remember = $latest;
                         //echo $package->packageversion . ' (score: ' . $remember['packagescore'] . ') from ' . $package->reponame .' repo id: ' . $package->repoid . " is already the latest, maybe it was reimported by hand for some reason\n";
                     } else {
                         //echo $package->packageversion . " is already the latest, this is probably from an other project; check if it was ever promoted\n";
                         $predecessors = self::get_predecessors($package->packageguid, 3);
                         if (count($predecessors)) {
                             foreach ($predecessors as $key => $guid) {
                                 //echo "compare: " . $guid . ' vs ' . $latest['packageguid'] . "\n";
                                 if ($guid == $latest['packageguid'] || isset($remember) && $guid == $remember['packageguid'] && $remember['packagescore'] > 0 && $remember['packagescore'] > $package->packagescore) {
                                     //echo "this version: " . $package->packageversion . ' was promoted on ' . $package->packagecreated->format('Y-m-d h:i e') . "\n";
                                     $promotedfromguid = $guid;
                                     if ($remember) {
                                         //echo "update history backwards";
                                         $all[$remember['released']]['promotedtoguid'] = $remember['packageguid'];
                                         $all[$remember['released']]['type'] = $promoted;
                                         $remember = false;
                                     } else {
                                         $promotedtoguid = $package->packageguid;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $all[$latest['released']] = array('size' => $latest['size'], 'repoid' => $latest['repoid'], 'version' => $latest['version'], 'variants' => $latest['variants'], 'released' => $latest['released'], 'packageid' => $latest['packageid'], 'packageguid' => $latest['packageguid'], 'packagescore' => $latest['packagescore'], 'hidden' => $latest['hidden'], 'publishers' => $latest['publishers'], 'localurl' => isset($latest['localurl']) ? $latest['localurl'] : false);
                 if ($latest['promotedfromguid']) {
                     $latest['type'] = $qarelease;
                     $all[$latest['released']]['promotedfromguid'] = $latest['promotedfromguid'];
                 } else {
                     if ($promotedtoguid) {
                         $latest['type'] = $promoted;
                         $all[$latest['released']]['promotedtoguid'] = $promotedtoguid;
                         $promotedtoguid = '';
                     } else {
                         $latest['type'] = $staging;
                     }
                 }
                 $all[$latest['released']]['type'] = $latest['type'];
                 $latest = $default_latest;
             }
             $latest['ux'] = $package->ux;
             $latest['size'] = $package->packagesize ? (int) ($package->packagesize / 1024) . ' kb' : 'n/a';
             $latest['publishers'] = self::get_roles($package->packageguid, 'downloader');
             $latest['repoid'] = $package->repoid;
             $latest['hidden'] = $package->packagehidden;
             $latest['version'] = $package->packageversion;
             $latest['released'] = $package->packagecreated->format('Y-m-d H:i');
             // @todo: this might not be needed
             $latest['variants'][$package->repoarch] = $variant_info;
             $latest['packageid'] = $package->packageid;
             $latest['lastupdate'] = $package->packagerevised->format('Y-m-d H:i');
             $latest['packageguid'] = $package->packageguid;
             $latest['packagename'] = $package->packagename;
             $latest['packagescore'] = $package->packagescore;
             if ($promotedfromguid) {
                 $latest['promotedfromguid'] = $promotedfromguid;
                 if (!$latest['hidden']) {
                     $latest['localurl'] = $package->localurl;
                 }
                 $promotedfromguid = '';
             } else {
                 if ($promotedtoguid) {
                     $latest['promotedtoguid'] = $promotedtoguid;
                     $promotedtoguid = '';
                 } else {
                     if (!$latest['hidden']) {
                         $latest['localurl'] = '/staging' . $package->localurl;
                     }
                 }
             }
         } elseif ($latest['version'] > $package->packageversion) {
             // this should not happen if the packages are ordered by version
             // anyway this package should go to all
             //echo $package->packageversion . ' from ' . $package->repoprojectname . ' goes to all' . "\n";
             $all[$package->packagecreated->format('Y-m-d H:i')] = $package->packageguid;
         }
         // add the latest to the all array
         $all[$latest['released']] = array('size' => $latest['size'], 'repoid' => $latest['repoid'], 'version' => $latest['version'], 'variants' => $latest['variants'], 'released' => $latest['released'], 'packageid' => $latest['packageid'], 'packageguid' => $latest['packageguid'], 'packagescore' => $latest['packagescore'], 'hidden' => $latest['hidden'], 'publishers' => $latest['publishers'], 'localurl' => isset($latest['localurl']) ? $latest['localurl'] : false);
         if ($latest['promotedfromguid']) {
             $all[$latest['released']]['type'] = $qarelease;
             $all[$latest['released']]['promotedfromguid'] = $latest['promotedfromguid'];
         } else {
             $all[$latest['released']]['type'] = $staging;
         }
         //echo "\n\n";
         //ob_flush();
         // set the default download url for the package
         if (array_key_exists($index, $latest['variants']) && !$this->data['packages'][$package->packagename]['defaultdownloadurl']) {
             // index was set at the beginning of this method
             $this->data['packages'][$package->packagename]['defaultdownloadurl'] = $latest['variants'][$index]['packageinstallfileurl'];
             // set a different downloadurl in case the configured download schema for this OS is 'apps'
             if (array_key_exists('download', $this->mvc->configuration->os_ux[$latest['variants'][$index]['repoos']]) && $this->mvc->configuration->os_ux[$latest['variants'][$index]['repoos']]['download'] == 'apps') {
                 $this->data['packages'][$package->packagename]['defaultdownloadurl'] = 'apps://' . $latest['variants'][$index]['packageid'];
             }
         }
         // set the latest of this package
         if (!array_key_exists('latest', $this->data['packages'][$package->packagename])) {
             $this->data['packages'][$package->packagename]['latest'] = array('version' => '', 'variants' => array());
         }
         if ($this->data['packages'][$package->packagename]['latest']['version'] <= $latest['version']) {
             $this->data['packages'][$package->packagename]['latest'] = $latest;
         }
         // always keep it up-to-date
         $this->data['packages'][$package->packagename]['all'] = $all;
         switch ($filter_type) {
             case 'staging':
                 $route_id = 'staging_apps_by_name';
                 break;
             case 'top':
             default:
                 $route_id = 'apps_by_name';
         }
         $this->data['packages'][$package->packagename]['localurl'] = $this->mvc->dispatcher->generate_url($route_id, array('os' => $package->repoos, 'version' => $package->repoosversion, 'ux' => is_array($matched) && array_key_exists('ux', $matched) ? $matched['ux'] : $package->ux, 'basecategory' => com_meego_packages_controllers_package::determine_base_category($package), 'packagename' => $package->packagename), $this->request);
         // do not bother any further for hidden instances
         if ($package->packagehidden) {
             continue;
         }
         // get the workflows for this package
         // todo: this will get workflows for all versions
         if (!array_key_exists('workflows', $this->data['packages'][$package->packagename])) {
             $this->data['packages'][$package->packagename]['workflows'] = array();
         }
         // get workflows, if any
         $workflows = self::get_workflows($package);
         if (is_array($workflows)) {
             $this->data['packages'][$package->packagename]['workflows'] = $workflows;
         }
     }
     //foreach
     if (isset($package)) {
         // let's unset the default variant, so we don't list it among the "other downloads"
         unset($this->data['packages'][$package->packagename]['latest']['variants'][$index]);
     }
     /*
             if (   isset($package)
                 && array_key_exists($package->packagename, $this->data['packages']))
             {
                 $latestversion = $this->data['packages'][$package->packagename]['latest']['version'];
                 if (array_key_exists($latestversion, $this->data['packages'][$package->packagename]['all']))
                 {
                     // always remove the latest from the all array
                     unset($this->data['packages'][$package->packagename]['all'][$latestversion]);
                 }
             }
     */
     // and we don't need this either
     unset($latest);
     if (isset($this->data['packages'])) {
         return $this->data['packages'];
     }
 }
Ejemplo n.º 6
0
 /**
  * Populates relations, such as
  *
  * - runtime dependency packages
  * - build dependency packages
  * - provided packages
  * - obsoleted packages
  * - suggested packages
  * - conflicting packages
  *
  * @param object extinfo which is a Package object
  * @param object package which is a com_meego_package object
  *
  */
 public function addRelations($extinfo = null, $package = null)
 {
     // check if package is referred in a relation
     // and update the relation record's 'to' field unless
     // it has been set already
     $qc = new midgard_query_constraint_group('AND');
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('toname'), '=', new midgard_query_value($package->filename)));
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('version'), '=', new midgard_query_value($package->version)));
     $q = new midgard_query_select(new midgard_query_storage('com_meego_package_relation'));
     $q->set_constraint($qc);
     $q->execute();
     $relations = $q->list_objects();
     if (!count($relations)) {
         $this->log('           package is not required by others');
     } else {
         // repo of the current package
         $repository_a = new com_meego_repository();
         $repository_a->get_by_id($package->repository);
         foreach ($relations as $relation) {
             if ($relation->to != 0) {
                 $this->log('           package is in relation but "to" field is already set. relation id: ' . $relation->id);
                 continue;
             }
             // get the related package object
             $related_package = new com_meego_package();
             $related_package->get_by_id($relation->from);
             // repo of the related package
             $repository_b = new com_meego_repository();
             $repository_b->get_by_id($related_package->repository);
             if ($repository_a->arch == $repository_b->arch) {
                 // we can safely update the to field of this relation
                 $this->log('           package is in relation with ' . $relation->from . ', update "to" field. relation id:' . $relation->id);
                 $_relation = new com_meego_package_relation($relation->guid);
                 $_relation->to = $package->id;
                 $_relation->update();
             }
         }
         unset($relations, $_relation);
     }
     if (is_array($extinfo->depends)) {
         /* delete relations that are no longer needed */
         $this->cleanRelations('requires', $extinfo->depends, $package);
         foreach ($extinfo->depends as $dependency) {
             $this->createRelation('requires', $dependency, $package);
         }
     }
     if (is_array($extinfo->buildDepends)) {
         /* delete relations that are no longer needed */
         $this->cleanRelations('buildrequires', $extinfo->buildDepends, $package);
         foreach ($extinfo->buildDepends as $dependency) {
             $this->createRelation('buildrequires', $dependency, $package);
         }
     }
     if (is_array($extinfo->provides)) {
         /* delete relations that are no longer needed */
         $this->cleanRelations('provides', $extinfo->provides, $package);
         foreach ($extinfo->provides as $provided) {
             $this->createRelation('provides', $provided, $package);
         }
     }
     if (is_array($extinfo->obsoletes)) {
         /* delete relations that are no longer needed */
         $this->cleanRelations('obsoletes', $extinfo->obsoletes, $package);
         foreach ($extinfo->obsoletes as $obsoleted) {
             $this->createRelation('obsoletes', $obsoleted, $package);
         }
     }
     if (is_array($extinfo->suggests)) {
         /* delete relations that are no longer needed */
         $this->cleanRelations('suggests', $extinfo->suggests, $package);
         foreach ($extinfo->suggests as $suggested) {
             $this->createRelation('suggests', $suggested, $package);
         }
     }
     if (is_array($extinfo->conflicts)) {
         /* delete relations that are no longer needed */
         $this->cleanRelations('conflicts', $extinfo->conflicts, $package);
         foreach ($extinfo->conflicts as $conflicted) {
             $this->createRelation('conflicts', $conflicted, $package);
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Process vote posts
  */
 public function post_vote(array $args)
 {
     $auth = false;
     $ocs = new com_meego_ocs_OCSWriter();
     if ($this->user) {
         $auth = true;
     } else {
         // Voting requires authentication
         $auth = com_meego_ocs_utils::authenticate($args);
     }
     if ($auth) {
         $primary = new com_meego_package();
         $primary->get_by_id((int) $args['contentid']);
         if (!$primary->guid) {
             $this->mvc->log(__CLASS__, 'Package with id:  (with id:' . $args['contentid'] . ') can not be found', 'info');
             $ocs->writeError('Content not found', 101);
         } else {
             $voted = false;
             // the multiple voting is configurable, pls check the config file
             if (!$this->mvc->configuration->allow_multiple_voting) {
                 // if not allowed then check if the user has voted already
                 if (com_meego_ocs_utils::user_has_voted($primary->id, $this->user->person)) {
                     $this->mvc->log(__CLASS__, "{$this->user}->login has already voted for {$primary->name} (with id: {$primary->id}) and multiple votings are disabled", 'info');
                     $ocs->writeError('Multiple voting not allowed and user has already voted this object.', 103);
                 }
             }
             if (!$ocs->error) {
                 $rating = new com_meego_ratings_rating();
                 $rating->to = $primary->guid;
                 $vote = $_POST['vote'];
                 // incoming votes are ranging between 0 and 100
                 // our internal scale is different: 0 - 5
                 $vote = round($vote / 20);
                 if ($vote > $this->mvc->configuration->maxrate) {
                     $vote = $this->mvc->configuration->maxrate;
                 }
                 $rating->rating = $vote;
                 // for votes only we have no comments
                 $rating->comment = 0;
                 if (!$rating->create()) {
                     $this->mvc->log(__CLASS__, 'Failed to create rating object. User: '******', application: ' . $primary->name . ' (with id: ' . $primary->id . ')', 'info');
                     throw new midgardmvc_exception_notfound("Could not create rating object");
                 }
                 $args = array('to' => $rating->to);
                 com_meego_ratings_caching_controllers_rating::calculate_average($args);
                 $ocs->writeMeta(0);
                 $this->mvc->log(__CLASS__, 'Rating (' . $rating->rating . ') submitted by ' . $this->user->login . ' for ' . $primary->name . ' (with id: ' . $primary->id . ')', 'info');
                 // create activity object
                 $verb = 'rate';
                 $summary = 'The user rated an application via OCS.';
                 $res = midgardmvc_account_controllers_activity::create_activity($rating->metadata->creator, $verb, $rating->to, $summary, 'Apps', $rating->metadata->created);
             }
         }
     } else {
         // extend the OCS spec with a custom status code
         $this->mvc->log(__CLASS__, 'Attempt to vote by anonymous. No luck.', 'info');
         $ocs->writeError('Voting requires authentication. Please login first.', 102);
     }
     $ocs->endDocument();
     self::output_xml($ocs);
 }