History of PortingTikiWikiPackages
Version 17
PortingTikiWikiPackages
Created by: Stephan Borg, Last modification: 20 Jul 2005 (11:34 UTC) by Stephan Borg
This is documentation of the process used while porting Trackers V2 from TikiWiki 1.9 to bitweaver.
{CODE()}$ mkdir trackers2
$ mkdir trackers2/admin
$ mkdir trackers2/icons
$ mkdir trackers2/modules
$ mkdir trackers2/plugins
$ mkdir trackers2/templates{CODE}
...tiki-view_tracker_item.php
...tiki-view_tracker_more_info.php
...tiki-view_tracker.php{CODE}
...tiki-admin_tracker_fields.php
...tiki-admin_trackers.php{CODE}
...mod-last_tracker_items.php{CODE}
...mod-last_tracker_items.tpl
...mod-usergroup_tracker.tpl{CODE}
...wikiplugin_trackerlist.php{CODE}
...tiki-admin_tracker_fields.tpl
...tiki-admin_trackers.tpl
...tiki-list_trackers.tpl
...tiki-plugin_trackerlist.tpl
...tiki-view_tracker_item.tpl
...tiki-view_tracker_more_info.tpl
...tiki-view_tracker.tpl{CODE}
{CODE()}<?php
header ("location: sheets.php");
die;
?>{CODE}
{CODE()}$ perl -i -pe 's/tiki-setup.php/..\/bit_setup_inc.php/g' `find trackers2 -type f -name '*.php'`{CODE}
Now create a bit_setup_inc.php file in the trackers2 directory. I've used the trackers/bit_setup_inc.php file as a template.
{CODE(colors=>php)}<?php
// Initialise global variables
global $gBitSystem, $gBitUser;
// Register package with kernel
$gBitSystem->registerPackage( 'Trackers v2', dirname( FILE ).'/' );
// If package is installed
if( $gBitSystem->isPackageActive( 'trackers2' ) )
{
// Register user menu
$gBitSystem->registerAppMenu( TRACKERS2_PKG_DIR, TRACKERS2_PKG_NAME, TRACKERS2_PKG_URL.'index.php',
'bitpackage:trackers2/menu_trackers.tpl', true );
/*
if( $gBitUser->hasPermission($gBitUser->getUserId(), 'bit_p_admin_trackers') )
{
$perms = $userlib->get_permissions(0, -1, 'perm_name_desc', '', 'trackers');
foreach ($perms"data" as $perm)
{
$perm = $perm"perm_name";
$smarty->assign("$perm", 'y');
$$perm = 'y';
}
}
$smarty->assign('t_use_db', 'y');
$smarty->assign('t_use_dir', '');
?>{CODE}
perl -i -pe "s/\'lib\/trackers\//TRACKERS2_PKG_PATH.\'/g" `find trackers2 -type f -name '*.php'`
...page...
CREATE TABLE tiki_trackers (
trackerId int(12) NOT NULL auto_increment,
name varchar(80) default NULL,
description text,
created int(14) default NULL,
lastModif int(14) default NULL,
showCreated char(1) default NULL,
showStatus char(1) default NULL,
showLastModif char(1) default NULL,
useComments char(1) default NULL,
showComments char(1) default NULL,
useAttachments char(1) default NULL,
showAttachments char(1) default NULL,
orderAttachments varchar(255) NOT NULL default 'filename,created,filesize,downloads,desc',
items int(10) default NULL,
PRIMARY KEY (trackerId)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
We need to create an AdoDB DataDict PHP file to create the tables as required. I have used the trackers file as a template and created trackers2/admin/schema_inc.php. This file shows how SQL create scripts are converted into DataDict PHP scripts. For more information, see DataDictTutorial.
{CODE(colors=>php)}<?php
$tables = array(
'tiki_trackers' => "
tracker_id I4 AUTO PRIMARY,
name C(80),
description X,
created I8,
lastModif I8,
showCreated C(1),
showStatus C(1),
showLastModif C(1),
useComments C(1),
showComments C(1),
useAttachments C(1),
showAttachments C(1),
orderAttachments C(255) NOTNULL DEFAULT 'filename,created,filesize,downloads,desc',
items I8
",
...
);
global $gTikiInstaller;
foreach( array_keys( $tables ) AS $tableName ) {
$gTikiInstaller->registerSchemaTable( TRACKERS2_PKG_DIR, $tableName, $tables$tableName );
}{CODE}
After each of the tables have been specified, you would specify the indices. In this case, there are none.
Next we specify the inserts. These usually consist of permissions and default preferences.
{CODE(colors=>php)}$gTikiInstaller->registerSchemaDefault( TRACKERS2_PKG_DIR, array(
"INSERT INTO `".TIKI_DB_PREFIX."users_permissions` (`perm_name`, `perm_desc`, `level`, `package`)
VALUES ('tiki_p_admin_trackers', 'Can admin trackers', 'editors', 'trackers')",
...
"INSERT INTO `".TIKI_DB_PREFIX."tiki_preferences`(`package`,`name`,`value`) VALUES ('trackers2',
'feature_trackers', 'n')"
) );
?>{CODE}
...page...
{CODE(colors=>smarty)}{tr}List trackers{/tr}
{if $tiki_p_admin_trackers eq 'y'}
{tr}Admin trackers{/tr}
{/if}{CODE}
mv trackers2/admin/tiki-admin_trackers.php trackers2/admin/admin_tracker2_inc.php
Now we have to create the Admin menu. Again the trackers/templates/menu_trackers2_admin.tpl is based on a similar file found in the trackers package.
{CODE(colors=>smarty)}{if $tiki_p_admin_trackers eq 'y'}
{tr}Trackers Settings{/tr}
{/if}{CODE}
Now, create the trackers2/admin/index.php file as shown below.
{CODE(colors=>php)}<?php
// This is not a package.
header ("location: ../index.php");
?>{CODE}
{CODE()}$ find -type f -exec perl -i -wpe 's/tiki-//g' {} \;{CODE}
At this point, we can begin testing. Browse to http://your.tp.install/kernel/admin/index.php and click on Trackers 2 Settings.
Create the Directories
Well, first thing I'll do is create sub-dirs under my bitweaver install as per Fire's Tutorial_Custom_package.{CODE()}$ mkdir trackers2
$ mkdir trackers2/admin
$ mkdir trackers2/icons
$ mkdir trackers2/modules
$ mkdir trackers2/plugins
$ mkdir trackers2/templates{CODE}
Copying the Files
First thing I'll do is copy the trackers library, root php files, modules and templates. I've used the '...' to indicate the previous command but with a different filename for brevity.Libraries
{CODE()}$ cp ../tw-1.9/lib/trackers/trackerlib.php trackers2{CODE}Root files (non-admin)
{CODE()}$ cp ../tw-1.9/tiki-list_trackers.php trackers2...tiki-view_tracker_item.php
...tiki-view_tracker_more_info.php
...tiki-view_tracker.php{CODE}
Root files (admin)
{CODE()}$ cp ../tw-1.9/tiki-admin_include_trackers.php trackers2/admin...tiki-admin_tracker_fields.php
...tiki-admin_trackers.php{CODE}
Icons
{CODE()}$ cp ../tw-1.9/img/icons/admin_trackers.png trackers2/icons{CODE}Modules
{CODE()}$ cp ../tw-1.9/modules/mod-last_modif_tracker_items.php trackers2/modules...mod-last_tracker_items.php{CODE}
Templates (modules)
{CODE()}$ cp ../tw-1.9/templates/modules/mod-last_modif_tracker_items.tpl trackers2/modules...mod-last_tracker_items.tpl
...mod-usergroup_tracker.tpl{CODE}
Wiki Plugins
{CODE()}$ cp ../tw-1.9/lib/wiki-plugins/wikiplugin_tracker.php trackers2/plugins...wikiplugin_trackerlist.php{CODE}
Templates (non-modules)
{CODE()} cp ../tw-1.9/templates/tiki-admin-include-trackers.tpl trackers2/templates...tiki-admin_tracker_fields.tpl
...tiki-admin_trackers.tpl
...tiki-list_trackers.tpl
...tiki-plugin_trackerlist.tpl
...tiki-view_tracker_item.tpl
...tiki-view_tracker_more_info.tpl
...tiki-view_tracker.tpl{CODE}
Templates (notifications)
{CODE()}$ cp ../tw-1.9/templates/mail/tracker_changed_notification.tpl trackers2/templates{CODE}Renaming files
Its BW practise to remove the tiki- prefix from all PHP and Smarty templates.Looking for PERL function to do this automatically
index.php
Lets start with an index page. By default, we want list trackers to be the index page. Rather than rename the page, I'd suggest creating a new index.php file, and using a Location header to redirect to your preferred start page.{CODE()}<?php
header ("location: sheets.php");
die;
?>{CODE}
bit_setup_inc.php
Okay - all references to tiki-setup.php must be changed to ../bit_setup_inc.php. I've used a PERL command that will find and replace all instances of tiki-setup.php to ../bit_setup_inc.php in all *.php files under trackers2 directory.{CODE()}$ perl -i -pe 's/tiki-setup.php/..\/bit_setup_inc.php/g' `find trackers2 -type f -name '*.php'`{CODE}
Now create a bit_setup_inc.php file in the trackers2 directory. I've used the trackers/bit_setup_inc.php file as a template.
{CODE(colors=>php)}<?php
// Initialise global variables
global $gBitSystem, $gBitUser;
// Register package with kernel
$gBitSystem->registerPackage( 'Trackers v2', dirname( FILE ).'/' );
// If package is installed
if( $gBitSystem->isPackageActive( 'trackers2' ) )
{
// Register user menu
$gBitSystem->registerAppMenu( TRACKERS2_PKG_DIR, TRACKERS2_PKG_NAME, TRACKERS2_PKG_URL.'index.php',
'bitpackage:trackers2/menu_trackers.tpl', true );
/*
if( $gBitUser->hasPermission($gBitUser->getUserId(), 'bit_p_admin_trackers') )
{
$perms = $userlib->get_permissions(0, -1, 'perm_name_desc', '', 'trackers');
foreach ($perms"data" as $perm)
{
$perm = $perm"perm_name";
$smarty->assign("$perm", 'y');
$$perm = 'y';
}
}
$smarty->assign('t_use_db', 'y');
$smarty->assign('t_use_dir', '');
- /
?>{CODE}
Libraries
Okay - all references to lib/trackers/trackerlib.php must be changed to TRACKERS2_PKG_PATH.'tracker_lib.php'. Once again, we will use a PERL find and replace.perl -i -pe "s/\'lib\/trackers\//TRACKERS2_PKG_PATH.\'/g" `find trackers2 -type f -name '*.php'`
...page...
Database Schema
Now for table creation - the TW1.9 database schema for Trackers 2 is quite lengthy, but we will use the main one as an example and explain the rest of the conversion in less detail. The main trackers table is as follows:CREATE TABLE tiki_trackers (
trackerId int(12) NOT NULL auto_increment,
name varchar(80) default NULL,
description text,
created int(14) default NULL,
lastModif int(14) default NULL,
showCreated char(1) default NULL,
showStatus char(1) default NULL,
showLastModif char(1) default NULL,
useComments char(1) default NULL,
showComments char(1) default NULL,
useAttachments char(1) default NULL,
showAttachments char(1) default NULL,
orderAttachments varchar(255) NOT NULL default 'filename,created,filesize,downloads,desc',
items int(10) default NULL,
PRIMARY KEY (trackerId)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
We need to create an AdoDB DataDict PHP file to create the tables as required. I have used the trackers file as a template and created trackers2/admin/schema_inc.php. This file shows how SQL create scripts are converted into DataDict PHP scripts. For more information, see DataDictTutorial.
{CODE(colors=>php)}<?php
$tables = array(
'tiki_trackers' => "
tracker_id I4 AUTO PRIMARY,
name C(80),
description X,
created I8,
lastModif I8,
showCreated C(1),
showStatus C(1),
showLastModif C(1),
useComments C(1),
showComments C(1),
useAttachments C(1),
showAttachments C(1),
orderAttachments C(255) NOTNULL DEFAULT 'filename,created,filesize,downloads,desc',
items I8
",
...
);
global $gTikiInstaller;
foreach( array_keys( $tables ) AS $tableName ) {
$gTikiInstaller->registerSchemaTable( TRACKERS2_PKG_DIR, $tableName, $tables$tableName );
}{CODE}
After each of the tables have been specified, you would specify the indices. In this case, there are none.
Next we specify the inserts. These usually consist of permissions and default preferences.
{CODE(colors=>php)}$gTikiInstaller->registerSchemaDefault( TRACKERS2_PKG_DIR, array(
"INSERT INTO `".TIKI_DB_PREFIX."users_permissions` (`perm_name`, `perm_desc`, `level`, `package`)
VALUES ('tiki_p_admin_trackers', 'Can admin trackers', 'editors', 'trackers')",
...
"INSERT INTO `".TIKI_DB_PREFIX."tiki_preferences`(`package`,`name`,`value`) VALUES ('trackers2',
'feature_trackers', 'n')"
) );
?>{CODE}
...page...
Making the Menu
TP menus are different from TW. We have to cut the menu items out of TW's templates/modules/mod-application_menu.tpl and create a trackers2/templates/menu_trackers2.tpl. I found the menu template from trackers package was suitable with some modification.{CODE(colors=>smarty)}{tr}List trackers{/tr}
{if $tiki_p_admin_trackers eq 'y'}
{tr}Admin trackers{/tr}
{/if}{CODE}
Making the Admin Menu
First we have to rename the main Trackers2 admin page.mv trackers2/admin/tiki-admin_trackers.php trackers2/admin/admin_tracker2_inc.php
Now we have to create the Admin menu. Again the trackers/templates/menu_trackers2_admin.tpl is based on a similar file found in the trackers package.
{CODE(colors=>smarty)}{if $tiki_p_admin_trackers eq 'y'}
{tr}Trackers Settings{/tr}
{/if}{CODE}
Now, create the trackers2/admin/index.php file as shown below.
{CODE(colors=>php)}<?php
// This is not a package.
header ("location: ../index.php");
?>{CODE}
Removing remaining tiki- references
Next, I run a very destructive script **BEWARE** - that removes all tiki- prefixes within all files.{CODE()}$ find -type f -exec perl -i -wpe 's/tiki-//g' {} \;{CODE}
Initial Testing
At this point, we can begin testing. Browse to http://your.tp.install/kernel/admin/index.php and click on Trackers 2 Settings.