All pastes #340542 Raw Edit

Untitled

public text v1 · immutable
·published 2007-02-04 21:07 UTC
rendered paste body
<?php
require_once('rpc.inc');

/**
 * Callback for hook_xmlrpc().
 *
 * Return versioning data a given project or for all available projects.
 * The version returned is the highest available for a given major and minor
 * release. These data can be used e.g. by applications on client sites to
 * determine whether the client sites have the latest available version.
 *
 * This call will only be effective for projects that have official versions.
 *
 * @param $project
 *   The 'short name' (stored as 'url') of a project, or the keyword 'all'
 *   for all projects. May be an array of projects.
 * @param $api_version
 *   The API version to get data for, as defined by the taxonomy. In Drupal
 *   this will be 5.x, 4.7.x, 4.6.x, etc.
 * @param $major_version
 *   Optionally, the major version to check for. If unspecified it will use
 *   the default major version as specified by the
 *   {project_release_default_version} table. This should usually be blank.
 * function project_release_data($project = NULL, $api_version = NULL, $major_version = NULL)
 * array('project', 'poormanscron', 'ecommerce')
 */
function get_release_data(
  $project = array('project', 'poormanscron','ecommerce','acidfree','akismet'),
  $api_version = '4.7.x',
  $major_version = NULL)
  {
  global $res;
  global $textBuffer;
  global $loops;
  global $t1, $t2;

  $host    = 'scratch.drupal.org';
  $port    = 80;
  $backend = '/xmlrpc.php';
  $request = xmlrpc_encode_request('project.release.data',
    array($project, $api_version, $major_version));
  //print_r($request);
  $t1 = time();
  for ($i = 0 ; $i < $loops ; $i++)
    $response = do_call_raw($host, $port, $backend, $request);
  $t2 = time();
  print_r($response);
  $res = xmlrpc_decode($response);
  /* if (xmlrpc_is_fault($res))
    {
    trigger_error("xmlrpc: $res[faultString] ($res[faultCode])");
    }
  else
    {
    echo "fetch success";
    }*/
  if ($project === 'all')
    {
    $res = unserialize($res);
    }
    $projects = array();
    foreach ($res as $project)
      {
  	  $projects[] = implode(' / ', $project);
      }
    $releases = print_r($projects, true);
    $releases .= "\nDuration: " . ($t2 - $t1) . " seconds";
    $textBuffer->set_text($releases);
  }

error_reporting(E_ALL);

$window = new GtkWindow();
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->set_size_request( 800, 1000 );      # set window size
$window->set_position(Gtk::WIN_POS_CENTER); # place window to screen center
$window->set_title("Drupal Project RPC test");

$res = 'click "fetch"';
$window->connect_simple('destroy', array('Gtk','main_quit'));

$vbox = new GtkVBox();
$window->add($vbox);

$btn = new GtkButton("Fetch project info");
$btn->connect_simple('clicked', 'get_release_data');
$vbox->pack_start($btn, false, false, 0);

$loops = 100;

$textBuffer = new GtkTextBuffer();
$textView   = new GtkTextView();
$textView->set_buffer($textBuffer);
$textView->set_editable(false);

$scroll = new GtkScrolledWindow();
$scroll->add($textView);

$vbox->add($scroll);

$window->show_all();
Gtk::main();