Blog

Mediawiki CSV Import ver 2.2.1 Released (Coupon Codes!)

PRONIQUE Software is proud to announce a new version Mediawiki CSV Import. Version 2.2.1 introduces the Dataset Library, a collection of contributed datasets that you can import and use to build your own Mediawiki Import files.

You must be a registered user to import or download the datasets. Membership is only $7.99 (one time) and helps support the development of the tool. It’s still FREE to register and use the tool however exports are limited to 15 pages until you upgrade.

To mark the new release and spark interest we are giving away 25 free accounts! Use one of the coupon codes below to upgrade to a Paid account. Once you create an account, login and enter the coupon code on the Upgrade page.

SD3YD7
FD3GD3
MA1JT9
TA9DT5
TE4W2D
SF7XK4
SD8GW6
BN2DF4
OK5RT3
EP8GF4
ED9GR3
SW2FR3
FRIDAY9

Learn more and signup for a FREE account at http://mwcsvimport.pronique.com/


CakePHP: Reorder lft rght columns in Tree models

If you are using the Tree Behavior sometimes the lft and rght columns get out of sync, especially if you are adding and deleting records during development.  Add the following action function to your app/app_controller.php or controller of your choice.

    /**
    * This is a maint function to recover/reorder the
    * lft/rght columns of a tree model.
    *
    */
    public function recover_tree( ) {
        $modelClass = $this->modelClass;
        if ( property_exists( $this->$modelClass->Behaviors, 'Tree' ) ) {
            if ( !$this->$modelClass->recover() ) {
                echo 'Error recovering acl tree';
            } else {
                echo $modelClass . ' reordered.';
            }
        } else {
            echo $modelClass . ' is not a tree model';
        }
        exit;
    }

CakePHP’s Acls implementation also uses this same Tree table structure. Since Acos and Aros often don’t have their own controllers the following function will allow you to reorder the lft rght columns in one shot. Again, add this to your AppController or controller of choice.

    /**
    * This is a maint function to recover/reorder the
    *  lft/rght columns of the aco and aro models.
    *
    */
    public function recover_acl_tree( ) {
        App::Import('Model', 'Aco' );
        App::Import('Model', 'Aro' );
        $Aco = new Aco;
        $Aro = new Aro;
        if ( !$Aco->recover() || !$Aro->recover() ) {
            echo 'Error recovering acl tree';
        } else {
            echo 'Aros and Acos reordered.';
        }
        exit;
    }

These methods/actions are meant to be called manually as you feel needed. If you would rather call them from other controller actions I would suggest prepending ‘_’ to the method names making them methods rather than url accessible actions.


Starting a CakePHP 2.0 Project with cakeinit

The latest version of cakeinit (0.8.5) now includes support to create CakePHP 2.0 projects. To create a new project you only need two commands. This is an alternative to downloading the zip or tar.gz file and extracting.

# download cakeinit
curl http://cakeinit.pronique.com/cakeinit.php -o cakeinit.php
# Create an app called mycakeapp based on the cakephp-2.0 bundle
php ./cakeinit.php cakephp-2.0 mycakeapp

The cakephp-1.3 bundle has also been updated to pull the recently released CakePHP 1.3.11 version of the framework. If you get some ugly permission errors don’t forget to prepend sudo to the above commands.

Read more about cakeinit at http://cakeinit.pronique.com.


How to Import CSV Data into MediaWiki as pages

1.) Create a FREE account for the Mediawiki CSV Import tool.

2.) Upload your CSV file, making sure you have column names in the first row, ie.

State, Abbreviation, Population
Texas, TX, 24782302
California, CA, 36961664
Florida, FL, 18801310

3.) Define a Page Template by clicking on Add Template. The template can contain mediawiki mark and variable from your csv data file. The template you are defining represents one row of data per page.

Variables for the CSV example above would be {$State}, {$Abbreviation}, and {$Population}.

4.) Click Generate Merge File to build a Mediawiki XML Import file

5.) Download this xml file to your computer.

6.) Login to your Mediawiki site and goto Special Pages.

7.) Click on the Import Pages link and upload the XML file.

8.) That’s it, Mediawiki will show you a summary of imported pages that you can click and view.

Check out the Mediawiki CSV Import tool from PRONIQUE Software


Guide to CakePHP 2.0 Conventions

With the release of CakePHP 2.0 you will see some big changes. With the release of 2.0 alpha I decided it was time to start tinkering and getting ready for 1.x migrations and will start new development with 2.x. This page serves as a quick intro and reference to these changes. If you are familiar with 1.x I’ve provided some side-by-side comparison of code. (continue reading…)


Mediawiki CSV Import 2.1.0 Release

We have released a new version of Mediawiki CSV Import (mwcsvimport). The latest version is now a web app rather than a download/install. You must register and login to use the latest version of the tool.

You can upgrade to a paid account with a one-time payment of $7.99. This will remove a 15 page export limit of free accounts. The latest version is available at http://mwcsvimport.pronique.com/. Give it a go and don’t forget to send us your feedback and comments.

Mediawiki CSV Import

The latest version is available in multiple languages but we need your help translating. Read more: Translators Needed

Read the release notes for more info about the 2.1.0 release.


netotools.com launched

I have launched a new collection of web-based networking, the site and tools based are powered by CakePHP. Check it out at http://www.netotools.com


gearmandAdmin – A PHP class to query gearmand

This is a php class that connects to a running gearmand process and gets the ‘status’ and and list of ‘workers’. The response can be had as the raw response $gmAdmin->getStatusRaw() or as a structured array $gmAdmin->getStatus().

Usage and Examples

require('gearmandAdmin.php');

//Create object from class sending host and port to connect on.
$gmAdmin = new gearmandAdmin( '127.0.0.1', 4730 );

// Outputs raw response from 'status' command
echo $gmAdmin->getStatusRaw();

//Example output from $gmAdmin->getStatusRaw();
ping       0       0       4
traceroute      0       0       4
whois   0       0       4
dig     0       0       4

// Outputs raw response from 'workers' command
echo $gmAdmin->getWorkersRaw();

//Example output from $gmAdmin->getWorkersRaw();
15 ::3875:6100:0:0%6386984 - :
14 ::3875:6100:0:0%6386984 - : ping traceroute whois dig
13 ::3875:6100:0:0%6386984 - : ping traceroute whois dig
12 ::3875:6100:0:0%6386984 - : ping traceroute whois dig
11 ::3875:6100:0:0%6386984 - : ping traceroute whois dig

// Returns array of status
print_r( $gmAdmin->getStatus() );

//Example output from $gmAdmin->getStatus();
Array
(
    [0] => Array
        (
            [function] => ping
            [total] => 0
            [running] => 0
            [workers] => 4
        )
    [1] => Array
        (
            [function] => traceroute
            [total] => 0
            [running] => 0
            [workers] => 4
        )
    [2] => Array
        (
            [function] => whois
            [total] => 0
            [running] => 0
            [workers] => 4
        )
    [3] => Array
        (
            [function] => dig
            [total] => 0
            [running] => 0
            [workers] => 4
        )
)

// Returns array of workers
print_r( $gmAdmin->getWorkers() );

// Example out from $gmAdmin->getWorkers()
Array
(
    [0] => Array
        (
            [descriptor] => 15
            [ip] => ::3875:6100:0:0%6386984
            [clientid] => -
        )
    [1] => Array
        (
            [descriptor] => 14
            [ip] => ::3875:6100:0:0%6386984
            [clientid] => -
            [functions] => Array
                (
                    [0] => ping
                    [1] => traceroute
                    [2] => whois
                    [3] => dig
                )
        )
    [2] => Array
        (
            [descriptor] => 13
            [ip] => ::3875:6100:0:0%6386984
            [clientid] => -
            [functions] => Array
                (
                    [0] => ping
                    [1] => traceroute
                    [2] => whois
                    [3] => dig
                )
        )
    [3] => Array
        (
            [descriptor] => 12
            [ip] => ::3875:6100:0:0%6386984
            [clientid] => -
            [functions] => Array
                (
                    [0] => ping
                    [1] => traceroute
                    [2] => whois
                    [3] => dig
                )
        )
    [4] => Array
        (
            [descriptor] => 11
            [ip] => ::3875:6100:0:0%6386984
            [clientid] => -
            [functions] => Array
                (
                    [0] => ping
                    [1] => traceroute
                    [2] => whois
                    [3] => dig
                )
        )
)

//Disconnect the TCP socket connection
$gmAdmin->disconnect();

The gearmandAdmin.php class

<?php
/**
 *
 * A PHP class to interface with gearmand's admin interface
 * This is a programable alternative to telneting to the
 * gearmand process (default port TCP 4730) and issuing the
 * commands 'status' and 'workers'
 * It is assumed that you have gearmand installed and running
 * as well, that you have the gearman pecl module install and enabled in
 * php.ini
 *
 * @license: GPLv3
 * @author: Jonathan Cutrer
 * @website: http://www.pronique.com
 *
 * If you find this tool useful consider linking to http:/www.pronique.com/
 * Or donate $5 via paypal, http://www.pronique.com/donate
 *
 *
 * Reference: http://gearman.org/index.php?id=protocol
 *
 */

class gearmandAdmin {

  private $socketHandle;
  private $host = '127.0.0.1';
  private $port = '4730';
  private $timeout = '5';

  function __construct( $host=null, $port=null, $timeout=null ) {
        if ( $host ) { $this->host = $host;}
        if ( $port ) { $this->port = $port;}
        if ( $timeout ) { $this->timeout = $timeout;}
        $this->connect();
  }

  /**
   * returns array of status
   *
   */
  function getStatus() {

    $response = $this->getStatusRaw();
    //TODO build $response in a structured array
    $count = 0;
    $lines = explode("\n", $response );
    foreach( $lines as $line ) {
        if ( $line =='.' ) { break; }
        $parts = explode("\t", $line);
        $status[$count]['function'] = $parts[0];
        $status[$count]['total'] = $parts[1];
        $status[$count]['running'] = $parts[2];
        $status[$count]['workers'] = $parts[3];
        $count++;
    }
    return $status;

  }

  /**
   * send the 'status' command to the server and return the raw response
   *
   */
  function getStatusRaw() {

    return $this->send('status');

  }

  /**
   * return array of workers
   *
   */
  function getWorkers() {

    $response = $this->getWorkersRaw();
    $lines = explode("\n", $response );
    //TODO build $response in a structured array
    $count = 0;
    foreach( $lines as $line ) {
        if ( $line =='.' ) { break; }
        $parts = explode(" ", $line);
        $workers[$count]['descriptor'] = $parts[0];
        $workers[$count]['ip'] = $parts[1];
        $workers[$count]['clientid'] = $parts[2];
        $func_marker = false;
        foreach( $parts as $part) {
            if ( $func_marker == true ) {
              $workers[$count]['functions'][] = $part;
            }
          if ($part == ':') { $func_marker = 1; }
        }
        $count++;
    }
    return $workers;

  }

  /**
   * send the 'workers' command to the server and return the raw response
   *
   */
  function getWorkersRaw() {

    return $this->send('workers');

  }

  /**
   * connect to gearmand using tcp
   *
   */
  function connect() {
    try {
      $this->socketHandle = fsockopen( $this->host, $this->port, $errno, $errstr, $this->timeout);
    } catch (Exception $e) {
      echo "Could not connect to gearmand server\n";
      echo "$errstr ($errno)\n";
    }
  }

  /**
   * disconnect from gearmand
   *
   */
  function disconnect() {
    fclose( $this->socketHandle );
  }

  /**
   * send a command to the socket
   *
   */
  function send( $cmd ) {
    $data = '';
    fwrite($this->socketHandle, $cmd . "\r\n");
    while (!feof($this->socketHandle)) {
         $data .= fgets($this->socketHandle, 1024);
         if ( preg_match("/\n\.$/i", $data ) ) { break; }
    }
    return $data;
  }
}
?>


gearman is a distributed job server consisting of a manager, workers, and clients. Learn more about it at http://gearman.org/. This code is released under the GPLv3 license, feel free to use it in your application. Drop me a line and tell me how and where you are using it.


CakePHP Developer Links

This page was started to store and organize a collective of CakePHP tutorials and useful links for PHP developers. Currently there are 122 articles and counting

(continue reading…)


Copyright © 1996-2010 PRONIQUE Software. All rights reserved.