cs-webapplibs-commits Mailing List for CS Web Application Libraries (Page 3)
Status: Beta
Brought to you by:
crazedsanity
You can subscribe to this list here.
| 2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(47) |
Sep
(8) |
Oct
(1) |
Nov
(3) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2010 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(3) |
Jun
(14) |
Jul
(5) |
Aug
|
Sep
(5) |
Oct
(2) |
Nov
|
Dec
|
| 2011 |
Jan
(15) |
Feb
(7) |
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(1) |
| 2012 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <cra...@us...> - 2010-06-21 15:54:22
|
Revision: 172
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=172&view=rev
Author: crazedsanity
Date: 2010-06-21 15:54:15 +0000 (Mon, 21 Jun 2010)
Log Message:
-----------
More changes for unit testing.
Modified Paths:
--------------
trunk/0.3/abstract/cs_genericGroup.abstract.class.php
trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php
trunk/0.3/cs_genericPermission.class.php
trunk/0.3/cs_phpDB.class.php
trunk/0.3/setup/genericPermissions.pgsql.sql
trunk/0.3/tests/testOfCSGenericPermissions.php
Removed Paths:
-------------
trunk/0.3/abstract/cs_group.abstract.class.php
Modified: trunk/0.3/abstract/cs_genericGroup.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_genericGroup.abstract.class.php 2010-06-21 15:12:12 UTC (rev 171)
+++ trunk/0.3/abstract/cs_genericGroup.abstract.class.php 2010-06-21 15:54:15 UTC (rev 172)
@@ -1,7 +1,6 @@
<?php
-
/*
- * Created on June 03, 2010
+ * Created on June 18, 2010
*
* FILE INFORMATION:
*
@@ -14,44 +13,51 @@
abstract class cs_genericGroupAbstract extends cs_webapplibsAbstract {
+ /** Database object. */
+ public $db;
+
+ /** cs_globalFunctions object, for cleaning strings & such. */
+ public $gfObj;
+
/** Table name used to store groups. */
const groupTable = "cswal_group_table";
/** Sequence for groups table. */
- const groupSeq = "cswal_group_table_group_id_seq";
+ const groupSeq = "cswal_group_table_group_id";
//============================================================================
- public abstract function __construct(cs_phpDB $db) {
- parent::__construct($db);
+ public function __construct(cs_phpDB $db) {
+ $this->db = $db;
+ $this->gfObj = new cs_globalFunctions;
}//end __construct()
//============================================================================
//============================================================================
- protected function clean_group_name($groupName) {
- try {
- $retval = $this->clean_permission_name($groupName);
+ protected function clean_group_name($name) {
+ if(!is_null($name) && is_string($name) && strlen($name)) {
+ $name = $this->gfObj->cleanString(strtolower($name), 'email');
}
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to clean group name (". $groupName .")");
+ else {
+ throw new exception(__METHOD__ .":: invalid string (". $name .")");
}
- return($retval);
}//end clean_group_name()
//============================================================================
//============================================================================
- public function create_group($groupName) {
- try {
- $groupName = $this->clean_group_name($groupName);
- $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $groupName ."')";
- $newId = $this->db->run_insert($sql, self::groupSeq);
+ public function create_group($name) {
+ try{
+ $name = $this->clean_group_name($name);
+ $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $name ."')";
+ $newId = $this->db->run_insert($sql, self::gropuSeq);
}
catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to create group (". $groupName ."), DETAILS::: ". $e->getMessage());
+ throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage());
}
+
return($newId);
}//end create_group()
//============================================================================
@@ -59,15 +65,16 @@
//============================================================================
- public function get_group($groupName) {
+ public function get_group($name) {
try {
- $groupName = $this->clean_group_name($groupName);
- $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $groupName ."'";
+ $name = $this->clean_group_name($name);
+ $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $name ."'";
$retval = $this->db->run_query($sql);
}
catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to locate group (". $groupName ."), DETAILS::: ". $e->getMessage());
+ throw new exception(__METHOD__ .":: error while locating group '". $name ."', DETAILS::: ". $e->getMessage());
}
+
return($retval);
}//end get_group()
//============================================================================
@@ -86,11 +93,30 @@
}
}
catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to locate group ID (". $groupId ."), DETAILS::: ". $e->getMessage());
+ throw new exception(__METHOD__ .":: error while locating group '". $groupId ."', DETAILS::: ". $e->getMessage());
}
+
return($retval);
}//end get_group_by_id()
//============================================================================
+
+
+ //============================================================================
+ /**
+ * Build the schema for the generic permissions system.
+ */
+ protected function build_schema() {
+ try {
+ $result = $this->db->run_sql_file(dirname(__FILE__) .'/../setup/genericPermissions.pgsql.sql');
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create schema, DETAILS::: ". $e->getMessage());
+ }
+ if($result !== true) {
+ throw new exception(__METHOD__ .":: failed to create schema (no details)");
+ }
+ }//end build_schema()
+ //============================================================================
}
?>
Modified: trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php 2010-06-21 15:12:12 UTC (rev 171)
+++ trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php 2010-06-21 15:54:15 UTC (rev 172)
@@ -21,7 +21,7 @@
const ugSeq = "cswal_user_group_table_user_group_id_seq";
//============================================================================
- public abstract function __construct(cs_phpDB $db) {
+ public function __construct(cs_phpDB $db) {
parent::__construct($db);
}//end __construct()
//============================================================================
@@ -36,7 +36,7 @@
$newId = $this->db->run_insert($sql, self::ugSeq);
}
catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to create group (". $groupName ."), DETAILS::: ". $e->getMessage());
+ throw new exception(__METHOD__ .":: failed to create user group, DETAILS::: ". $e->getMessage());
}
}
else {
Deleted: trunk/0.3/abstract/cs_group.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_group.abstract.class.php 2010-06-21 15:12:12 UTC (rev 171)
+++ trunk/0.3/abstract/cs_group.abstract.class.php 2010-06-21 15:54:15 UTC (rev 172)
@@ -1,122 +0,0 @@
-<?php
-/*
- * Created on June 18, 2010
- *
- * FILE INFORMATION:
- *
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-class cs_groupAbstract extends cs_webapplibsAbstract {
-
- /** Database object. */
- public $db;
-
- /** cs_globalFunctions object, for cleaning strings & such. */
- public $gfObj;
-
- /** Table name used to store groups. */
- const groupTable = "cswal_group_table";
-
- /** Sequence for groups table. */
- const groupSeq = "cswal_group_table_group_id";
-
- //============================================================================
- public abstract function __construct(cs_phpDB $db) {
- $this->db = $db;
- $this->gfObj = new cs_globalFunctions;
- }//end __construct()
- //============================================================================
-
-
-
- //============================================================================
- protected function clean_group_name($name) {
- if(!is_null($name) && is_string($name) && strlen($name)) {
- $name = $this->gfObj->cleanString(strtolower($name), 'email');
- }
- else {
- throw new exception(__METHOD__ .":: invalid string (". $name .")");
- }
- }//end clean_group_name()
- //============================================================================
-
-
-
- //============================================================================
- public function create_group($name) {
- try{
- $name = $this->clean_group_name($name);
- $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $name ."')";
- $newId = $this->db->run_insert($sql, self::gropuSeq);
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage());
- }
-
- return($newId);
- }//end create_group()
- //============================================================================
-
-
-
- //============================================================================
- public function get_group($name) {
- try {
- $name = $this->clean_group_name($name);
- $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $name ."'";
- $retval = $this->db->run_query($sql);
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: error while locating group '". $name ."', DETAILS::: ". $e->getMessage());
- }
-
- return($retval);
- }//end get_group()
- //============================================================================
-
-
-
- //============================================================================
- public function get_group_by_id($groupId) {
- try {
- if(!is_null($groupId) && is_numeric($groupId)) {
- $sql = "SELECT * FROM ". self::groupTable ." WHERE group_id='". $groupId ."'";
- $retval = $this->db->run_query($sql);
- }
- else {
- throw new exception(__METHOD__ .":: invalid group ID (". $groupId .")");
- }
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: error while locating group '". $groupId ."', DETAILS::: ". $e->getMessage());
- }
-
- return($retval);
- }//end get_group_by_id()
- //============================================================================
-
-
-
- //============================================================================
- /**
- * Build the schema for the generic permissions system.
- */
- private function build_schema() {
- try {
- $result = $this->db->run_sql_file(dirname(__FILE__) .'/../setup/genericPermissions.pgsql.sql');
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to create schema, DETAILS::: ". $e->getMessage());
- }
- if($result !== true) {
- throw new exception(__METHOD__ .":: failed to create schema (no details)");
- }
- }//end build_schema()
- //============================================================================
-}
-?>
Modified: trunk/0.3/cs_genericPermission.class.php
===================================================================
--- trunk/0.3/cs_genericPermission.class.php 2010-06-21 15:12:12 UTC (rev 171)
+++ trunk/0.3/cs_genericPermission.class.php 2010-06-21 15:54:15 UTC (rev 172)
@@ -29,7 +29,7 @@
protected $keys = array();
//============================================================================
- public abstract function __construct(cs_phpDB $db) {
+ public function __construct(cs_phpDB $db) {
$this->db = $db;
parent::__construct($db);
$this->gfObj = new cs_globalFunctions;
@@ -70,7 +70,7 @@
//handle it like an array.
for($x=0;$x<strlen($string);$x++) {
$myVal = false;
- if($string[$x] !== '-')
+ if($string[$x] !== '-') {
$myVal = true;
}
$key = $this->keys[$x];
@@ -176,7 +176,7 @@
//============================================================================
public function get_object_by_id($objectId) {
- return($this->get_permission_by_id($objectId);
+ return($this->get_permission_by_id($objectId));
}//end get_object_by_id()
//============================================================================
Modified: trunk/0.3/cs_phpDB.class.php
===================================================================
--- trunk/0.3/cs_phpDB.class.php 2010-06-21 15:12:12 UTC (rev 171)
+++ trunk/0.3/cs_phpDB.class.php 2010-06-21 15:54:15 UTC (rev 172)
@@ -205,14 +205,8 @@
$this->lastSQLFile = $filename;
$fileContents = $fsObj->read($filename);
- try {
- $this->db->run_update($fileContents, true);
- $this->build_cache();
- $retval = TRUE;
- }
- catch(exception $e) {
- $retval = FALSE;
- }
+ $this->run_update($fileContents, true);
+ $retval = TRUE;
return($retval);
}//end run_sql_file()
Modified: trunk/0.3/setup/genericPermissions.pgsql.sql
===================================================================
--- trunk/0.3/setup/genericPermissions.pgsql.sql 2010-06-21 15:12:12 UTC (rev 171)
+++ trunk/0.3/setup/genericPermissions.pgsql.sql 2010-06-21 15:54:15 UTC (rev 172)
@@ -7,7 +7,7 @@
CREATE TABLE cswal_group_table (
group_id serial NOT NULL PRIMARY KEY,
group_name text NOT NULL UNIQUE,
- group_admin integer NOT NULL REFERENCES cs_authtentication_table(uid)
+ group_admin integer REFERENCES cs_authentication_table(uid)
);
--
Modified: trunk/0.3/tests/testOfCSGenericPermissions.php
===================================================================
--- trunk/0.3/tests/testOfCSGenericPermissions.php 2010-06-21 15:12:12 UTC (rev 171)
+++ trunk/0.3/tests/testOfCSGenericPermissions.php 2010-06-21 15:54:15 UTC (rev 172)
@@ -20,6 +20,7 @@
if(!defined('CS_UNITTEST')) {
throw new exception(__METHOD__ .": FATAL: constant 'CS_UNITTEST' not set, can't do testing safely");
}
+ $this->get_valid_users();
}//end __construct()
//--------------------------------------------------------------------------
@@ -65,12 +66,40 @@
//--------------------------------------------------------------------------
+ /**
+ * Just like the schema, this SQL will need to change to match your database in order to work.
+ */
+ private function get_valid_users() {
+ $sql = "SELECT uid,username FROM cs_authentication_table ORDER BY uid";
+ $db = $this->create_dbconn();
+ $this->validUsers = $db->run_query($sql);
+ $this->gfObj->debug_print($this->validUsers);
+ }//end get_valid_users()
+ //--------------------------------------------------------------------------
+
+
+
+ //--------------------------------------------------------------------------
public function test_userGroups() {
- $perm = new cs_genericPermission($this->create_dbconn());
+ $perm = new _gpTester($this->create_dbconn());
+ $perm->do_schema();
+
+ //create a group with an invalid group_id.
+ $perm->create_user_group($this->validUsers[0]['uid'],1);
}//end test_userGroups
//--------------------------------------------------------------------------
}
+
+class _gpTester extends cs_genericPermission {
+ public function __construct($db) {
+ parent::__construct($db);
+ }
+
+ public function do_schema() {
+ $this->build_schema();
+ }
+}
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-06-21 15:12:18
|
Revision: 171
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=171&view=rev
Author: crazedsanity
Date: 2010-06-21 15:12:12 +0000 (Mon, 21 Jun 2010)
Log Message:
-----------
Minor changes to make tests work, separate out the generic permissions stuff into its own test file.
Modified Paths:
--------------
trunk/0.3/tests/testOfCSWebAppLibs.php
Added Paths:
-----------
trunk/0.3/tests/testOfCSGenericPermissions.php
Copied: trunk/0.3/tests/testOfCSGenericPermissions.php (from rev 170, trunk/0.3/tests/testOfCSWebAppLibs.php)
===================================================================
--- trunk/0.3/tests/testOfCSGenericPermissions.php (rev 0)
+++ trunk/0.3/tests/testOfCSGenericPermissions.php 2010-06-21 15:12:12 UTC (rev 171)
@@ -0,0 +1,76 @@
+<?php
+/*
+ * Created on June 21, 2010
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+class testOfCSGenericPermissions extends UnitTestCase {
+
+ //--------------------------------------------------------------------------
+ function __construct() {
+ $this->gfObj = new cs_globalFunctions;
+ $this->gfObj->debugPrintOpt=1;
+ if(!defined('CS_UNITTEST')) {
+ throw new exception(__METHOD__ .": FATAL: constant 'CS_UNITTEST' not set, can't do testing safely");
+ }
+ }//end __construct()
+ //--------------------------------------------------------------------------
+
+
+
+ //--------------------------------------------------------------------------
+ private function create_dbconn() {
+ $dbParams = array(
+ 'host' => constant('cs_webapplibs-DB_CONNECT_HOST'),
+ 'dbname' => constant('cs_webapplibs-DB_CONNECT_DBNAME'),
+ 'user' => constant('cs_webapplibs-DB_CONNECT_USER'),
+ 'password' => constant('cs_webapplibs-DB_CONNECT_PASSWORD'),
+ 'port' => constant('cs_webapplibs-DB_CONNECT_PORT')
+ );
+ $db = new cs_phpDB(constant('DBTYPE'));
+ $db->connect($dbParams);
+ return($db);
+ }//end create_dbconn()
+ //--------------------------------------------------------------------------
+
+
+
+ //--------------------------------------------------------------------------
+ private function remove_tables() {
+ $tableList = array(
+ 'cswal_gdl_object_table', 'cswal_gdl_attribute_table', 'cswal_gdl_path_table',
+ 'cswal_object_table', 'cswal_user_group_table', 'cswal_group_table'
+ );
+
+ $db = $this->create_dbconn();
+ foreach($tableList as $name) {
+ try {
+ $db->run_update("DROP TABLE ". $name ." CASCADE", true);
+ }
+ catch(exception $e) {
+ //force an error.
+ //$this->assertTrue(false, "Error while dropping (". $name .")::: ". $e->getMessage());
+ }
+ }
+ }//end remove_tables()
+ //--------------------------------------------------------------------------
+
+
+
+ //--------------------------------------------------------------------------
+ public function test_userGroups() {
+ $perm = new cs_genericPermission($this->create_dbconn());
+ }//end test_userGroups
+ //--------------------------------------------------------------------------
+
+
+
+}
+?>
Modified: trunk/0.3/tests/testOfCSWebAppLibs.php
===================================================================
--- trunk/0.3/tests/testOfCSWebAppLibs.php 2010-06-21 14:41:53 UTC (rev 170)
+++ trunk/0.3/tests/testOfCSWebAppLibs.php 2010-06-21 15:12:12 UTC (rev 171)
@@ -37,7 +37,7 @@
$db = new cs_phpDB(constant('DBTYPE'));
$db->connect($dbParams);
return($db);
- }//end create_db()
+ }//end create_dbconn()
//--------------------------------------------------------------------------
@@ -48,8 +48,7 @@
'cswal_auth_token_table', 'cswal_version_table', 'cswal_attribute_table',
'cswal_category_table', 'cswal_class_table', 'cswal_event_table',
'cswal_log_attribute_table', 'cswal_log_table', 'cswal_session_store_table',
- 'cswal_gdl_object_table', 'cswal_gdl_attribute_table', 'cswal_gdl_path_table',
- 'cswal_object_table', 'cswal_user_group_table', 'cswal_group_table'
+ 'cswal_gdl_object_table', 'cswal_gdl_path_table', 'cswal_gdl_attribute_table'
);
$db = $this->create_dbconn();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-06-21 14:42:00
|
Revision: 170
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=170&view=rev
Author: crazedsanity
Date: 2010-06-21 14:41:53 +0000 (Mon, 21 Jun 2010)
Log Message:
-----------
Resurrect cs_genericDataLinker, fix some unit tests (uncomment them, fix method references).
Modified Paths:
--------------
trunk/0.3/tests/testOfCSWebAppLibs.php
Added Paths:
-----------
trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php
trunk/0.3/abstract/cs_gdlObject.abstract.class.php
trunk/0.3/abstract/cs_gdlPath.abstract.class.php
trunk/0.3/cs_genericDataLinker.class.php
Copied: trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php (from rev 165, trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php 2010-06-21 14:41:53 UTC (rev 170)
@@ -0,0 +1,89 @@
+<?php
+/*
+ * Created on Jan 29, 2009
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_gdlAttribAbstract extends cs_gdlPathAbstract {
+
+
+ const table='cswal_gdl_attribute_table';
+ const tableSeq = 'cswal_gdl_attribute_table_attribute_id_seq';
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_attrib($path, $data, $type=null) {
+
+ $objectId = $this->get_object_id_from_path($path);
+
+ $insertString = "";
+ $attribs = array();
+ if(is_array($data) && count($data)) {
+ foreach($data as $n=>$v) {
+ $n = $this->translate_attrib_name($n);
+ $attribs[$n] = $v;
+ }
+ }
+ elseif(!is_null($type)) {
+ $key = $this->translate_attrib_name($type);
+ $attribs = array($key => $data);
+ }
+ else {
+ throw new exception(__METHOD__ .": data was not array and no type set");
+ }
+
+ if(!is_array($attribs) || !count($attribs)) {
+ throw new exception(__METHOD__ .": failed to create an array of attributes... ". $this->gfObj->debug_print(func_get_args(),0));
+ }
+
+ $attribs['object_id'] = $objectId;
+ $insertString = $this->gfObj->string_from_array($attribs, 'insert');
+
+
+ if(!strlen($insertString)) {
+ throw new exception(__METHOD__ .": invalid insert string (". $insertString .")");
+ }
+ $sql = "INSERT INTO ". self::attrTable ." ". $insertString;
+
+ try {
+ $retval = $this->db->run_insert($sql, self::attrTableSeq);
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": failed to perform insert::: ". $e->getMessage() .' ---- '. $sql);
+ }
+
+ return($retval);
+ }//end create_attrib()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function translate_attrib_name($name) {
+ $retval = null;
+ foreach($this->validTypes as $type) {
+ if(preg_match('/^'. $type .'/', $name)) {
+ $retval = 'a_'. $type;
+ break;
+ }
+ }
+
+ if(is_null($retval) || !strlen($retval)) {
+ $this->gfObj->debug_print(__METHOD__ .": name was (". $name ."), retval=(". $retval .")",1);
+ throw new exception(__METHOD__ .": invalid attribute name (". $name .")");
+ }
+
+ return($retval);
+ }//end translate_attrib_name()
+ //-------------------------------------------------------------------------
+
+}
+?>
\ No newline at end of file
Copied: trunk/0.3/abstract/cs_gdlObject.abstract.class.php (from rev 165, trunk/0.3/abstract/cs_gdlObject.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_gdlObject.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_gdlObject.abstract.class.php 2010-06-21 14:41:53 UTC (rev 170)
@@ -0,0 +1,136 @@
+<?php
+/*
+ * Created on Jan 29, 2009
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_gdlObjectAbstract extends cs_webapplibsAbstract {
+
+
+ const table='cswal_gdl_object_table';
+ const tableSeq = 'cswal_gdl_object_table_object_id_seq';
+
+ //-------------------------------------------------------------------------
+ public function get_object_id_from_path($path) {
+ $sql = "SELECT object_id FROM ". self::table ." WHERE object_path='".
+ $this->clean_path($path) ."'";
+
+ try {
+ $data = $this->db->run_query($sql);
+
+ if(is_array($data) && count($data) == 1) {
+ $retval = $data['object_id'];
+ }
+ else {
+ throw new exception(__METHOD__ .": invalid data for path (". $this->clean_path($path) .")::: ". $this->gfObj->debug_var_dump($data,0));
+ }
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": error retrieving path::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end get_object_id_from_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_object($name, $data=null, $type=null) {
+ $sql = "INSERT INTO ". self::table ." (object_name) VALUES ('".
+ $this->gfObj->cleanString($this->clean_path($name), 'sql_insert') ."')";
+ try {
+ $retval = $this->db->run_insert($sql, self::tableSeq);
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": failed to perform insert::: ". $e->getMessage());
+ }
+
+ if(!is_null($data)) {
+ throw new exception(__METHOD__ .": can't create data for objects yet");
+ }
+ return($retval);
+ }//end create_object()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function build_object_id_list(array $objects) {
+ $this->gfObj->switch_force_sql_quotes(1);
+ $sql = "SELECT * FROM ". self::table ." WHERE object_name IN (".
+ $this->gfObj->string_from_array($objects, null, ',', 'sql') .")";
+ $this->gfObj->switch_force_sql_quotes(0);
+
+ $retval = array();
+ try {
+ $retval = $this->db->run_query($sql, 'object_name', 'object_id');
+ if(!is_array($retval)) {
+ $retval = array();
+ }
+ }
+ catch(exception $e) {
+ //throw new exception(__METHOD__ .": failed to retrieve list");
+ }
+
+ return($retval);
+ }//end build_object_id_list()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function build_object_name_list(array $objectIds) {
+ $this->gfObj->switch_force_sql_quotes(1);
+//string_from_array($array,$style=NULL,$separator=NULL, $cleanString=NULL, $removeEmptyVals=FALSE)
+ foreach($objectIds as $i=>$myId) {
+ if(!strlen($myId)) {
+ unset($objectIds[$i]);
+ }
+ }
+ $sql = "SELECT * FROM ". self::table ." WHERE object_id IN (".
+ $this->gfObj->string_from_array($objectIds, null, ',', 'sql',true) .")";
+ $this->gfObj->switch_force_sql_quotes(0);
+
+ try {
+ $retval = $this->db->run_query($sql, 'object_id', 'object_name');
+ if(!is_array($retval)) {
+ $retval = array();
+ }
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": failed to retrieve list::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end build_object_id_list()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_objects_enmasse(array $objectList) {
+ $retval = 0;
+ foreach($objectList as $name) {
+ try {
+ $this->create_object($name);
+ $retval++;
+ }
+ catch(exception $e) {
+ //nothing to see here, move along.
+ }
+ }
+ return($retval);
+ }//end create_objects_enmasse()
+ //-------------------------------------------------------------------------
+
+
+}
+?>
Copied: trunk/0.3/abstract/cs_gdlPath.abstract.class.php (from rev 165, trunk/0.3/abstract/cs_gdlPath.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_gdlPath.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_gdlPath.abstract.class.php 2010-06-21 14:41:53 UTC (rev 170)
@@ -0,0 +1,126 @@
+<?php
+/*
+ * Created on Jan 29, 2009
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_gdlPathAbstract extends cs_gdlObjectAbstract {
+
+
+ const table='cswal_gdl_path_table';
+ const tableSeq = 'cswal_gdl_path_table_path_id_seq';
+
+
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_path($path) {
+ $idList = $this->create_path_objects($path);
+ $pathIdList = $this->create_id_path($idList);
+
+ if($this->get_path_from_idlist($pathIdList)) {
+ $retval = $pathIdList;
+ }
+ else {
+
+ $sql = "INSERT INTO ". self::table ." (path_id_list) VALUES ('". $pathIdList ."')";
+
+ try {
+ $insertedId = $this->db->run_insert($sql, self::tableSeq);
+ $retval = $pathIdList;
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": unable to create path::: ". $e->getMessage());
+ }
+ }
+
+ return($retval);
+ }//end create_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function clean_path($path, $appendBase=true) {
+ if(strlen($path)) {
+ if($appendBase === true && !is_null($this->basePath)) {
+ $path = $this->basePath .'/'. $path;
+ }
+ $newPath = preg_replace('/\/{2,}/', '/', $path);
+
+ if(!strlen($newPath)) {
+ throw new exception(__METHOD__ .": new path is zero-length (". $newPath ."), old path=(". func_get_arg(0) .")");
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": no valid path given (". $path .")");
+ }
+
+ return($newPath);
+ }//end clean_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function set_base_path($path) {
+ if(is_null($path) || !strlen($path)) {
+ $this->basePath = null;
+ }
+ else {
+ $this->basePath = $this->clean_path($path,false);
+ }
+ }//end set_base_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function explode_path($path, $appendBase=true) {
+ $path = $this->clean_path($path, $appendBase);
+ $path = preg_replace('/^\//', '', $path);
+ $path = preg_replace('/\/$/', '', $path);
+
+ return(explode('/', $path));
+ }//end explode_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_id_path(array $idList) {
+ $retval = ':'. $this->gfObj->string_from_array($idList, null, '::') .':';
+ return($retval);
+ }//end create_id_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function get_path_from_idlist($idPath) {
+
+ $idList = explode('::', preg_replace('/^:/', '', preg_replace('/:$/', '', $idPath)));
+
+ $nameList = $this->build_object_name_list($idList);
+
+ $retval = "/";
+ foreach($nameList as $id=>$name) {
+ $retval = $this->gfObj->create_list($retval, $name, '/');
+ }
+
+ $retval = $this->clean_path($retval,false);
+
+ return($retval);
+ }//end get_text_path_from_id_path()
+ //-------------------------------------------------------------------------
+
+}
+?>
\ No newline at end of file
Copied: trunk/0.3/cs_genericDataLinker.class.php (from rev 165, trunk/0.3/cs_genericDataLinker.class.php)
===================================================================
--- trunk/0.3/cs_genericDataLinker.class.php (rev 0)
+++ trunk/0.3/cs_genericDataLinker.class.php 2010-06-21 14:41:53 UTC (rev 170)
@@ -0,0 +1,101 @@
+<?php
+/*
+ * Created on Oct 27, 2009
+ *
+ * THE IDEA:::
+ * 1.) Unix/Linux-like paths lead to an attribute.
+ * 2.) Multiple paths can lead to the same attribute.
+ * 3.) An attribute can be linked to its original path.
+ * 4.) Each "directory" in a path is an object with an ID.
+ * 5.) Paths themselves are only stored on attributes: intermediate paths may be valid if all objects
+ * for that path are also valid (i.e. if "/one/two/three" is valid, so is "/two/one/three" and "/three/two/one").
+ * 6.) Database...
+ * a.) finding an attribute referencing a single object should be straightforward and fast.
+ * b.) objects are unique to avoid excess duplicate pathways
+ * c.) using id paths with each number wrapped in colons is simple (i.e. ":3342:", ":3342::3::3:"
+ *
+ * The idea here is to have a class that generically links data together (in a
+ * database). It is not meant to be a super clean or speedy system, instead meant
+ * as a way of describing relationships between various pieces of data.
+ *
+ * Once a path is created (list object_id's, separated by '::'), it should always have an attribute.
+ *
+ *
+ * 1::2::3 -> select * from <bla> WHERE path = '2' OR path like '2::%' OR path like '%::2'
+ * -OR-
+ * :1::2::3: -> select * from <bla> WHERE path like '%:2:%'
+ *
+ * If an attribute is created with a small path (like "/test") and the id is 1, the attribute shows ":1:"
+ * --> if the id is 7720218, then the attribute shows ":7720218:"
+ *
+ *
+ * SVN INFORMATION:::
+ * -------------------
+ * Last Author::::::::: $Author$
+ * Current Revision:::: $Revision$
+ * Repository Location: $HeadURL$
+ * Last Updated:::::::: $Date$
+ */
+
+
+
+class cs_genericDataLinker extends cs_gdlAttribAbstract {
+
+ const attrTable='cswal_gdl_attribute_table';
+ const attrTableSeq='cswal_gdl_attribute_table_attribute_id_seq';
+
+ protected $validTypes = array('text', 'int', 'dec', 'bool');
+ protected $gfObj;
+ protected $basePath=null;
+
+ public $db;
+
+ //-------------------------------------------------------------------------
+ public function __construct(cs_phpDB $db) {
+
+ parent::__construct($db);
+ if(!$db->is_connected()) {
+ throw new exception(__METHOD__ .": database not connected");
+ }
+ $this->db = $db;
+ $this->gfObj = new cs_globalFunctions;
+ }//end __construct()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_path_objects($path) {
+ $newPath = $this->clean_path($path);
+ $newPath = preg_replace('/^\//', '', $newPath);
+
+ //break it into bits.
+ $bits = explode('/', $newPath);
+
+ $myList = $this->build_object_id_list($bits);
+ if(count($myList) !== count($bits)) {
+ $createThese = array();
+ foreach($bits as $name) {
+ if(!isset($myList[$name])) {
+ $createThese[] = $name;
+ }
+ }
+ $this->create_objects_enmasse($createThese);
+ $myList = $this->build_object_id_list($bits);
+ }
+
+ $retval = array();
+ foreach($bits as $name) {
+ @$retval[$name] = $myList[$name];
+ }
+
+ if(is_null($retval) || !is_array($retval) || !count($retval)) {
+ throw new exception(__METHOD__ .": failed to build path objects... ". $retval);
+ }
+
+ return($retval);
+ }//end create_path_objects()
+ //-------------------------------------------------------------------------
+}
+
+?>
Modified: trunk/0.3/tests/testOfCSWebAppLibs.php
===================================================================
--- trunk/0.3/tests/testOfCSWebAppLibs.php 2010-06-21 14:29:53 UTC (rev 169)
+++ trunk/0.3/tests/testOfCSWebAppLibs.php 2010-06-21 14:41:53 UTC (rev 170)
@@ -203,7 +203,7 @@
//--------------------------------------------------------------------------
- function tst_genericDataLinker() {
+ function test_genericDataLinker() {
$x = new gdlTester($this->create_dbconn());
@@ -260,7 +260,7 @@
}
- /*/basic tests for building text-based paths vs. id-based paths.
+ //basic tests for building text-based paths vs. id-based paths.
{
$myPath = '/character/sheet/Tetra Tealeaf';
@@ -273,8 +273,8 @@
$idList2 = $x->create_path($myPath);
$this->assertEqual($x->create_id_path(array_values($idList)), $idList2);
- $this->assertEqual($myPath, $x->get_text_path_from_id_path($x->create_id_path($idList)));
- $this->gfObj->debug_var_dump($x->get_text_path_from_id_path($x->create_id_path($idList)));
+ $this->assertEqual($myPath, $x->get_path_from_idlist($x->create_id_path($idList)));
+ $this->gfObj->debug_var_dump($x->get_path_from_idlist($x->create_id_path($idList)));
$this->gfObj->debug_var_dump($idList);
$this->gfObj->debug_var_dump($idList2);
@@ -495,7 +495,6 @@
}
}
-/*
class gdlTester extends cs_genericDataLinker {
public $isTest = true;
@@ -507,6 +506,5 @@
return($this->create_path_objects($path));
}
}
-//*/
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-06-21 14:30:04
|
Revision: 169
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=169&view=rev
Author: crazedsanity
Date: 2010-06-21 14:29:53 +0000 (Mon, 21 Jun 2010)
Log Message:
-----------
Add generic permissions system, fix an error with upgrade system, documentation.
/docs/README.txt:
* added some documentation for CS Generic Permissions.
/setup/genericPermissions.pgsql.sql:
* no permission table anymore
* group_table has an admin (group_admin) column
* no more permission_group table
* added FKey to user_group table
* added object table with *nix-like permissions.
* added list of example permissions...
/tests/testOfCSWebAppLibs.php:
* remove_tables():
-- added tables for the permissions stuff.
* renamed "test_genericDataLinker()" to "tst_genericDataLinker()" so it
would not run (planning on resurrecting the generic data linker).
* commented-out the extra "gdlTester" class.
/abstract/cs_genericPermissionGroup.abstract.class.php [DELETED]
/abstract/cs_genericPermission.abstract.class.php [DELETED]
/abstract/cs_genericUserGroup.abstract.class.php [NEW,COPIED]:
* updated some internal vars & such for new class name.
/abstract/cs_genericGroup.abstract.class.php:
* extends cs_webapplibsAbstract
/abstract/cs_group.abstract.class.php [NEW,COPIED]:
* updated some internal vars & such for new class name.
/cs_genericPermission.class.php:
* MAIN:::
-- extends cs_genericUserGroup.
-- rename internal vars to reference the object table.
* __construct():
-- call parent constructor
-- setup keys array for permissions.
* clean_permission_name() [DELETED]:
-- handled in another class...
* _sanityCheck() [NEW]:
-- checks to make sure internal things are good.
* parse_permission_string() [NEW]:
-- parses a string like "rwxrw-r--" into the appropriate column names.
* build_permission_string() [NEW]:
-- create a string like "rwxrw-r--" (reverse of parse_permission_string()).
* create_object() [NEW]:
-- same as calling create_permission().
* create_permission():
-- revamped to use the object table.
* get_object() [NEW]:
-- like calling get_permission()
* get_permission():
-- updated to use the permission table.
* get_object_by_id() [NEW]:
-- just like calling get_permission_by_id().
* get_permission_by_id():
-- like the name implies.
/cs_webdbupgrade.class.php:
* get_database_version():
-- return data after table loaded (thanks to unit testing).
Modified Paths:
--------------
trunk/0.3/abstract/cs_genericGroup.abstract.class.php
trunk/0.3/cs_webdbupgrade.class.php
trunk/0.3/docs/README.txt
trunk/0.3/setup/genericPermissions.pgsql.sql
trunk/0.3/tests/testOfCSWebAppLibs.php
Added Paths:
-----------
trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php
trunk/0.3/abstract/cs_group.abstract.class.php
trunk/0.3/cs_genericPermission.class.php
Removed Paths:
-------------
trunk/0.3/abstract/cs_genericPermission.abstract.class.php
trunk/0.3/abstract/cs_genericPermissionGroup.abstract.class.php
Modified: trunk/0.3/abstract/cs_genericGroup.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_genericGroup.abstract.class.php 2010-06-15 02:16:11 UTC (rev 168)
+++ trunk/0.3/abstract/cs_genericGroup.abstract.class.php 2010-06-21 14:29:53 UTC (rev 169)
@@ -12,7 +12,7 @@
* $LastChangedRevision$
*/
-abstract class cs_genericGroupAbstract extends cs_genericPermissionAbstract {
+abstract class cs_genericGroupAbstract extends cs_webapplibsAbstract {
/** Table name used to store groups. */
const groupTable = "cswal_group_table";
Deleted: trunk/0.3/abstract/cs_genericPermission.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_genericPermission.abstract.class.php 2010-06-15 02:16:11 UTC (rev 168)
+++ trunk/0.3/abstract/cs_genericPermission.abstract.class.php 2010-06-21 14:29:53 UTC (rev 169)
@@ -1,122 +0,0 @@
-<?php
-/*
- * Created on June 03, 2010
- *
- * FILE INFORMATION:
- *
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-abstract class cs_genericPermissionAbstract extends cs_webapplibsAbstract {
-
- /** Database object. */
- public $db;
-
- /** cs_globalFunctions object, for cleaning strings & such. */
- public $gfObj;
-
- /** Table name used to store permissions. */
- const permTable = "cswal_permission_table";
-
- /** Sequence for permissions table. */
- const permSeq = "cswal_permission_table_permission_id";
-
- //============================================================================
- public abstract function __construct(cs_phpDB $db) {
- $this->db = $db;
- $this->gfObj = new cs_globalFunctions;
- }//end __construct()
- //============================================================================
-
-
-
- //============================================================================
- protected function clean_permission_name($name) {
- if(!is_null($name) && is_string($name) && strlen($name)) {
- $name = $this->gfObj->cleanString(strtolower($name), 'email');
- }
- else {
- throw new exception(__METHOD__ .":: invalid string (". $name .")");
- }
- }//end clean_permission_name()
- //============================================================================
-
-
-
- //============================================================================
- public function create_permission($name) {
- try{
- $name = $this->clean_permission_name($name);
- $sql = "INSERT INTO ". self::permTable ." (permission_name) VALUES ('". $name ."')";
- $newId = $this->db->run_insert($sql, self::permSeq);
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage());
- }
-
- return($newId);
- }//end create_permission()
- //============================================================================
-
-
-
- //============================================================================
- public function get_permission($name) {
- try {
- $name = $this->clean_permission_name($name);
- $sql = "SELECT * FROM ". self::permTable ." WHERE permission_name='". $name ."'";
- $retval = $this->db->run_query($sql);
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: error while locating permission '". $name ."', DETAILS::: ". $e->getMessage());
- }
-
- return($retval);
- }//end get_permission()
- //============================================================================
-
-
-
- //============================================================================
- public function get_permission_by_id($permId) {
- try {
- if(!is_null($permId) && is_numeric($permId)) {
- $sql = "SELECT * FROM ". self::permTable ." WHERE permission_id='". $permId ."'";
- $retval = $this->db->run_query($sql);
- }
- else {
- throw new exception(__METHOD__ .":: invalid permission ID (". $permId .")");
- }
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: error while locating permission '". $permId ."', DETAILS::: ". $e->getMessage());
- }
-
- return($retval);
- }//end get_permission_by_id()
- //============================================================================
-
-
-
- //============================================================================
- /**
- * Build the schema for permissions.
- */
- private function build_schema() {
- try {
- $result = $this->db->run_sql_file(dirname(__FILE__) .'/../setup/genericPermissions.pgsql.sql');
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to create schema, DETAILS::: ". $e->getMessage());
- }
- if($result !== true) {
- throw new exception(__METHOD__ .":: failed to create schema (no details)");
- }
- }//end build_schema()
- //============================================================================
-}
-?>
Deleted: trunk/0.3/abstract/cs_genericPermissionGroup.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_genericPermissionGroup.abstract.class.php 2010-06-15 02:16:11 UTC (rev 168)
+++ trunk/0.3/abstract/cs_genericPermissionGroup.abstract.class.php 2010-06-21 14:29:53 UTC (rev 169)
@@ -1,96 +0,0 @@
-<?php
-
-/*
- * Created on June 14, 2010
- *
- * FILE INFORMATION:
- *
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-abstract class cs_genericPermissionGroupAbstract extends cs_genericGroupAbstract {
-
- /** Table name used to store permission groups. */
- const permGroupTable = "cswal_permission_group_table";
-
- /** Sequence for permission_group table. */
- const groupSeq = "cswal_permission_group_table_permission_group_id_seq";
-
- //============================================================================
- public abstract function __construct(cs_phpDB $db) {
- parent::__construct($db);
- }//end __construct()
- //============================================================================
-
-
-
- //============================================================================
- protected function clean_perm_group_name($permGroupName) {
- try {
- $retval = $this->clean_group_name($permGroupName);
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to clean group name (". $groupName .")");
- }
- return($retval);
- }//end clean_perm_group_name()
- //============================================================================
-
-
-
- //============================================================================
- public function create_group($groupName) {
- try {
- $groupName = $this->clean_group_name($groupName);
- $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $groupName ."')";
- $newId = $this->db->run_insert($sql, self::groupSeq);
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to create group (". $groupName ."), DETAILS::: ". $e->getMessage());
- }
- return($newId);
- }//end create_group()
- //============================================================================
-
-
-
- //============================================================================
- public function get_group($groupName) {
- try {
- $groupName = $this->clean_group_name($groupName);
- $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $groupName ."'";
- $retval = $this->db->run_query($sql);
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to locate group (". $groupName ."), DETAILS::: ". $e->getMessage());
- }
- return($retval);
- }//end get_group()
- //============================================================================
-
-
-
- //============================================================================
- public function get_group_by_id($groupId) {
- try {
- if(!is_null($groupId) && is_numeric($groupId)) {
- $sql = "SELECT * FROM ". self::groupTable ." WHERE group_id='". $groupId ."'";
- $retval = $this->db->run_query($sql);
- }
- else {
- throw new exception(__METHOD__ .":: invalid group ID (". $groupId .")");
- }
- }
- catch(Exception $e) {
- throw new exception(__METHOD__ .":: failed to locate group ID (". $groupId ."), DETAILS::: ". $e->getMessage());
- }
- return($retval);
- }//end get_group_by_id()
- //============================================================================
-
-}
-?>
Copied: trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php (from rev 168, trunk/0.3/abstract/cs_genericGroup.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php 2010-06-21 14:29:53 UTC (rev 169)
@@ -0,0 +1,71 @@
+<?php
+
+/*
+ * Created on June 18, 2010
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_genericUserGroupAbstract extends cs_genericGroupAbstract {
+
+ /** Table name used to store user_group records. */
+ const ugTable = "cswal_user_group_table";
+
+ /** Sequence for user_group table. */
+ const ugSeq = "cswal_user_group_table_user_group_id_seq";
+
+ //============================================================================
+ public abstract function __construct(cs_phpDB $db) {
+ parent::__construct($db);
+ }//end __construct()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_user_group($userId, $groupId) {
+ if(is_numeric($userId) && is_numeric($groupId) && $userId >= 0 && $groupId >= 0) {
+ try {
+ $sql = "INSERT INTO ". self::ugTable ." (user_id, group_id) VALUES (". $userId .", ". $groupId .")";
+ $newId = $this->db->run_insert($sql, self::ugSeq);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create group (". $groupName ."), DETAILS::: ". $e->getMessage());
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid or non-numeric user_id (". $userId .") or group_id (". $groupId .")");
+ }
+ return($newId);
+ }//end create_group()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_user_groups($userId) {
+ if(is_numeric($userId) && $userId >= 0) {
+ try {
+ $sql = "SELECT ug.*, g.group_name FROM ". self::ugTable ." AS ug INNER "
+ ."JOIN ". parent::groupTable ." as g WHERE user_id=". $userId;
+ $retval = $this->db->run_query($sql);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to locate group (". $groupName ."), DETAILS::: ". $e->getMessage());
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid or non-numeric user_id (". $userId .")");
+ }
+ return($retval);
+ }//end get_group()
+ //============================================================================
+
+}
+?>
Copied: trunk/0.3/abstract/cs_group.abstract.class.php (from rev 168, trunk/0.3/abstract/cs_genericPermission.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_group.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_group.abstract.class.php 2010-06-21 14:29:53 UTC (rev 169)
@@ -0,0 +1,122 @@
+<?php
+/*
+ * Created on June 18, 2010
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+class cs_groupAbstract extends cs_webapplibsAbstract {
+
+ /** Database object. */
+ public $db;
+
+ /** cs_globalFunctions object, for cleaning strings & such. */
+ public $gfObj;
+
+ /** Table name used to store groups. */
+ const groupTable = "cswal_group_table";
+
+ /** Sequence for groups table. */
+ const groupSeq = "cswal_group_table_group_id";
+
+ //============================================================================
+ public abstract function __construct(cs_phpDB $db) {
+ $this->db = $db;
+ $this->gfObj = new cs_globalFunctions;
+ }//end __construct()
+ //============================================================================
+
+
+
+ //============================================================================
+ protected function clean_group_name($name) {
+ if(!is_null($name) && is_string($name) && strlen($name)) {
+ $name = $this->gfObj->cleanString(strtolower($name), 'email');
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid string (". $name .")");
+ }
+ }//end clean_group_name()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_group($name) {
+ try{
+ $name = $this->clean_group_name($name);
+ $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $name ."')";
+ $newId = $this->db->run_insert($sql, self::gropuSeq);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage());
+ }
+
+ return($newId);
+ }//end create_group()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_group($name) {
+ try {
+ $name = $this->clean_group_name($name);
+ $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $name ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: error while locating group '". $name ."', DETAILS::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end get_group()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_group_by_id($groupId) {
+ try {
+ if(!is_null($groupId) && is_numeric($groupId)) {
+ $sql = "SELECT * FROM ". self::groupTable ." WHERE group_id='". $groupId ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid group ID (". $groupId .")");
+ }
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: error while locating group '". $groupId ."', DETAILS::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end get_group_by_id()
+ //============================================================================
+
+
+
+ //============================================================================
+ /**
+ * Build the schema for the generic permissions system.
+ */
+ private function build_schema() {
+ try {
+ $result = $this->db->run_sql_file(dirname(__FILE__) .'/../setup/genericPermissions.pgsql.sql');
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create schema, DETAILS::: ". $e->getMessage());
+ }
+ if($result !== true) {
+ throw new exception(__METHOD__ .":: failed to create schema (no details)");
+ }
+ }//end build_schema()
+ //============================================================================
+}
+?>
Copied: trunk/0.3/cs_genericPermission.class.php (from rev 168, trunk/0.3/abstract/cs_genericPermission.abstract.class.php)
===================================================================
--- trunk/0.3/cs_genericPermission.class.php (rev 0)
+++ trunk/0.3/cs_genericPermission.class.php 2010-06-21 14:29:53 UTC (rev 169)
@@ -0,0 +1,204 @@
+<?php
+/*
+ * Created on June 03, 2010
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+class cs_genericPermission extends cs_genericUserGroupAbstract {
+
+ /** Database object. */
+ public $db;
+
+ /** cs_globalFunctions object, for cleaning strings & such. */
+ public $gfObj;
+
+ /** Table name used to store permissions. */
+ const objTable = "cswal_object_table";
+
+ /** Sequence for permissions table. */
+ const objSeq = "cswal_object_table_object_id";
+
+ /** List of valid keys... */
+ protected $keys = array();
+
+ //============================================================================
+ public abstract function __construct(cs_phpDB $db) {
+ $this->db = $db;
+ parent::__construct($db);
+ $this->gfObj = new cs_globalFunctions;
+ $this->keys = array(
+ 0 => 'u_r',
+ 1 => 'u_w',
+ 2 => 'u_x',
+ 3 => 'g_r',
+ 4 => 'g_w',
+ 5 => 'g_x',
+ 6 => 'o_r',
+ 7 => 'o_w',
+ 8 => 'o_x'
+ );
+ }//end __construct()
+ //============================================================================
+
+
+
+ //============================================================================
+ /**
+ * Checks internals to make sure all is okay; throws an exception on fail.
+ */
+ private function _sanityCheck() {
+ if(!is_array($this->keys) || count($this->keys) != 9) {
+ throw new exception(__METHOD__ .":: internal error, no keys");
+ }
+ }//end _sanityCheck()
+ //============================================================================
+
+
+
+ //============================================================================
+ protected function parse_permission_string($string) {
+ $this->_sanityCheck();
+ if(is_string($string) && strlen($string) == 9) {
+ $retval = array();
+ //handle it like an array.
+ for($x=0;$x<strlen($string);$x++) {
+ $myVal = false;
+ if($string[$x] !== '-')
+ $myVal = true;
+ }
+ $key = $this->keys[$x];
+ $retval[$key] = $myVal;
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid permission string (". $string ."), non-string or not 9 characters long (example: 'rwxrw-rw-')");
+ }
+ return($retval);
+ }//end parse_permission_string()
+ //============================================================================
+
+
+
+ //============================================================================
+ protected function build_permission_string(array $perms) {
+ $this->_sanityCheck();
+ if(is_array($perms) && count($perms) == count($this->keys)) {
+ $retval = "";
+ foreach($this->keys as $dbColName) {
+ if(isset($perms[$dbColName])) {
+ //get the last character of the column name.
+ $permChar = substring($dbColName, -1);
+ if($perms[$dbColName] === false) {
+ $permChar = '-';
+ }
+ $retval .= $permChar;
+ }
+ else {
+ throw new exception(__METHOD__ .":: missing permission index (". $dbColName .")");
+ }
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid permission set.");
+ }
+ return($retval);
+ }//end build_permission_string();
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_object($name, $userId, $groupId, $permString) {
+ return($this->create_permission($name, $userId, $groupId, $permString));
+ }//end create_object()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_permission($name, $userId, $groupId, $permString) {
+ if(is_string($name) && strlen($name) && is_numeric($userId) && $userId >= 0 && is_numeric($groupId) && $groupId >= 0) {
+ try{
+ $insertArr = $this->parse_permission_string($permString);
+ $insertArr['object_name'] = $this->gfObj->cleanString($name, 'sql', 0);
+ $insertArr['user_id'] = $userId;
+ $insertArr['group_id'] = $groupId;
+
+ $insertSql = $this->gfObj->string_from_array($insertArr, 'insert');
+ $sql = "INSERT INTO ". self::objTable ." ". $insertSql;
+ $newId = $this->db->run_insert($sql, self::objSeq);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage());
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid argument(s)");
+ }
+
+ return($newId);
+ }//end create_permission()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_object($name) {
+ return($this->get_permission($name));
+ }//end get_object()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_permission($name) {
+ try {
+ $name = $this->clean_permission_name($name);
+ $sql = "SELECT * FROM ". self::objTable ." WHERE permission_name='". $name ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: error while locating permission '". $name ."', DETAILS::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end get_permission()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_object_by_id($objectId) {
+ return($this->get_permission_by_id($objectId);
+ }//end get_object_by_id()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_permission_by_id($permId) {
+ try {
+ if(!is_null($permId) && is_numeric($permId)) {
+ $sql = "SELECT * FROM ". self::objTable ." WHERE object_id='". $permId ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid permission ID (". $permId .")");
+ }
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: error while locating permission '". $permId ."', DETAILS::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end get_permission_by_id()
+ //============================================================================
+}
+?>
Modified: trunk/0.3/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.3/cs_webdbupgrade.class.php 2010-06-15 02:16:11 UTC (rev 168)
+++ trunk/0.3/cs_webdbupgrade.class.php 2010-06-21 14:29:53 UTC (rev 169)
@@ -542,6 +542,11 @@
//now try the SQL...
$numrows = $this->db->exec($sql);
$dberror = $this->db->errorMsg();
+
+ //retrieve the data...
+ $data = $this->db->farray_fieldnames();
+ $this->databaseVersion = $data['version_string'];
+ $retval = $this->parse_version_string($data['version_string']);
}
else {
$this->error_handler(__METHOD__ .": no table in database, failed to create one... ORIGINAL " .
Modified: trunk/0.3/docs/README.txt
===================================================================
--- trunk/0.3/docs/README.txt 2010-06-15 02:16:11 UTC (rev 168)
+++ trunk/0.3/docs/README.txt 2010-06-21 14:29:53 UTC (rev 169)
@@ -90,4 +90,32 @@
NO:::
--> stop upgrade process.
--> HALT
- --> (continues as before)
\ No newline at end of file
+ --> (continues as before)
+
+
+=== CS Generic Permissions ===
+
+This permissions system is built to be flexible enough to be used in virtually any application for any purpose. The "permissions" are stored in a way that basically mimics *nix filesystem permissions. The code must know what the object is for which the user is asking permission. That object has the following traits:
+ * Object Name: the name of the item that is being assigned permissions.
+ -- Examples:
+ ++ A URL (i.e. "/authenticated" would only be accessible to the owner + group members)
+ ++ A Blog (i.e. "/blog/harryjohnson" would be readable to everyone, but only writeable by user "harryjohnson")
+ ++ A File (i.e. "/{WEBROOT}/files/hiddenData.sqlite" might only be allowed access by a certain user)
+ ++ Executing a special script: (i.e. "/bin/importFiles.pl", run script using a web interface)
+ * User ID: indicates what user owns this object.
+ * Group ID: indicates a group that users must be part of (if not owner) to be assigned these permissions
+ * Permission Bits:
+ -- Each permission is a true/false value. The name is in the form "{x}_{y}"
+ ++ "{x}": u/g/o (User/Group/Owner)
+ ++ "{y}": r/w/x (Read/Write/eXecute)
+ -- Full Explanation:
+ ++ "u_r": User's read permission; indicates if the owner can "read" (view) it.
+ ++ "u_w": User's write permission; indicates if the owner can write (create/update) the object.
+ ++ "u_x": User's execute permission; this rarely applies, and usage would vary greatly depending upon the object & associated code.
+ ++ "g_r": Group read permission; users assigned to the associated group can/cannot "read" (view) it.
+ ++ "g_w": Group write permission; users assigned to the associated group can/cannot write (create/update) the object.
+ ++ "g_x": Group execute permission; users assigned to the associated group are bound by this value (usage depends on code).
+ ++ "o_r": Other read permission; users that are not owners or members of the group can/cannot "read" (view) it
+ ++ "o_w": Other write permission; users that are not owners or members of the group can/cannot write (create/update) the object.
+ ++ "o_x": Other execute permission; users that are... you get the idea.
+
Modified: trunk/0.3/setup/genericPermissions.pgsql.sql
===================================================================
--- trunk/0.3/setup/genericPermissions.pgsql.sql 2010-06-15 02:16:11 UTC (rev 168)
+++ trunk/0.3/setup/genericPermissions.pgsql.sql 2010-06-21 14:29:53 UTC (rev 169)
@@ -1,58 +1,60 @@
+BEGIN;
--
--- Permission table
--- Specific permissions: these are words used by the code to determine if the user has the appropriate permission.
---
-CREATE TABLE cswal_permission_table (
- permission_id serial NOT NULL PRIMARY KEY,
- permission_name text NOT NULL UNIQUE
-);
-
-
---
-- Group table
-- Enumerates a list of permissions for a specific group: i.e. for "blog", this could list "create", "edit", and "delete" (among others).
--
CREATE TABLE cswal_group_table (
group_id serial NOT NULL PRIMARY KEY,
- group_name text NOT NULL UNIQUE
+ group_name text NOT NULL UNIQUE,
+ group_admin integer NOT NULL REFERENCES cs_authtentication_table(uid)
);
--
--- Permission + Group table
--- Enumerates permissions for a given group: any permissions not specifically entered are denied.
---
-CREATE TABLE cswal_permission_group_table (
- permission_group_id serial NOT NULL PRIMARY KEY,
- permission_id integer NOT NULL REFERENCES cswal_permission_table(permission_id),
- group_id integer NOT NULL REFERENCES cswal_group_table(group_id),
- allowed boolean NOT NULL DEFAULT false,
- description text
-);
-
---
-- User + Group table
-- Assigns a user to one or more groups.
--- NOTE::: the "user_id" column should be (manually) foreign-keyed to an existing user table.
+-- NOTE::: the "user_id" table should be updated to match your database schema.
--
CREATE TABLE cswal_user_group_table (
user_group_id serial NOT NULL PRIMARY KEY,
- user_id integer NOT NULL,
+ user_id integer NOT NULL REFERENCES cs_authentication_table(uid),
group_id integer NOT NULL REFERENCES cswal_group_table(group_id)
);
--
--- User + Permission table
--- Give users specific permissions, overriding default and/or assigned group permissions.
+-- Object table
+-- Contains unique list of objects along with the owner, default group, & user/group/other permissions (like *nix filesystem permissions)
+-- The permissions for user/group/other could be converted to octal (i.e. "rwxrwxrwx" == "777"), but it isn't as straightforward to read.
+-- NOTE::: the "user_id" table should be updated to match your database schema.
--
-CREATE TABLE cswal_user_permission_table (
- user_permission_id serial NOT NULL PRIMARY KEY,
- user_id integer NOT NULL,
+CREATE TABLE cswal_object_table (
+ object_id serial NOT NULL PRIMARY KEY,
+ object_name text NOT NULL UNIQUE,
+ user_id integer NOT NULL REFERENCES cs_authentication_table(uid),
group_id integer NOT NULL REFERENCES cswal_group_table(group_id),
- permission_id integer NOT NULL REFERENCES cswal_permission_table(permission_id),
- allowed boolean NOT NULL DEFAULT false
+ u_r boolean NOT NULL DEFAULT TRUE,
+ u_w boolean NOT NULL DEFAULT TRUE,
+ u_x boolean NOT NULL DEFAULT FALSE,
+ g_r boolean NOT NULL DEFAULT TRUE,
+ g_w boolean NOT NULL DEFAULT FALSE,
+ g_x boolean NOT NULL DEFAULT FALSE,
+ o_r boolean NOT NULL DEFAULT TRUE,
+ o_w boolean NOT NULL DEFAULT FALSE,
+ o_x boolean NOT NULL DEFAULT FALSE
);
+INSERT INTO cswal_group_table (group_name) VALUES ('www');
+INSERT INTO cswal_group_table (group_name) VALUES ('blogs');
+INSERT INTO cswal_group_table (group_name) VALUES ('admin');
+INSERT INTO cswal_object_table
+ (object_name,user_id, group_id)
+ VALUES
+ ('/', 101, 1);
+
+INSERT INTO cswal_object_table
+ (object_name, user_id, group_id, g_r, g_w)
+ VALUES
+ ('/member', 101, 2, true, true);
Modified: trunk/0.3/tests/testOfCSWebAppLibs.php
===================================================================
--- trunk/0.3/tests/testOfCSWebAppLibs.php 2010-06-15 02:16:11 UTC (rev 168)
+++ trunk/0.3/tests/testOfCSWebAppLibs.php 2010-06-21 14:29:53 UTC (rev 169)
@@ -48,7 +48,8 @@
'cswal_auth_token_table', 'cswal_version_table', 'cswal_attribute_table',
'cswal_category_table', 'cswal_class_table', 'cswal_event_table',
'cswal_log_attribute_table', 'cswal_log_table', 'cswal_session_store_table',
- 'cswal_gdl_object_table', 'cswal_gdl_attribute_table', 'cswal_gdl_path_table'
+ 'cswal_gdl_object_table', 'cswal_gdl_attribute_table', 'cswal_gdl_path_table',
+ 'cswal_object_table', 'cswal_user_group_table', 'cswal_group_table'
);
$db = $this->create_dbconn();
@@ -202,7 +203,7 @@
//--------------------------------------------------------------------------
- function test_genericDataLinker() {
+ function tst_genericDataLinker() {
$x = new gdlTester($this->create_dbconn());
@@ -458,6 +459,13 @@
//--------------------------------------------------------------------------
+ public function test_genericPermissions() {
+ }//end test_genericPermissions()
+ //--------------------------------------------------------------------------
+
+
+
+ //--------------------------------------------------------------------------
private function do_tokenTest(array $tokenData, $uid, $checksum) {
if($this->assertTrue(is_array($tokenData)) && $this->assertTrue(is_numeric($uid)) && $this->assertTrue(strlen($checksum))) {
@@ -487,6 +495,7 @@
}
}
+/*
class gdlTester extends cs_genericDataLinker {
public $isTest = true;
@@ -498,5 +507,6 @@
return($this->create_path_objects($path));
}
}
+//*/
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-06-15 02:16:18
|
Revision: 168
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=168&view=rev
Author: crazedsanity
Date: 2010-06-15 02:16:11 +0000 (Tue, 15 Jun 2010)
Log Message:
-----------
The beginnings of a generic permissions system.
Added Paths:
-----------
trunk/0.3/abstract/cs_genericGroup.abstract.class.php
trunk/0.3/abstract/cs_genericPermission.abstract.class.php
trunk/0.3/abstract/cs_genericPermissionGroup.abstract.class.php
trunk/0.3/docs/example_genericPermission.php
trunk/0.3/setup/genericPermissions.pgsql.sql
Copied: trunk/0.3/abstract/cs_genericGroup.abstract.class.php (from rev 162, trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_genericGroup.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_genericGroup.abstract.class.php 2010-06-15 02:16:11 UTC (rev 168)
@@ -0,0 +1,96 @@
+<?php
+
+/*
+ * Created on June 03, 2010
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_genericGroupAbstract extends cs_genericPermissionAbstract {
+
+ /** Table name used to store groups. */
+ const groupTable = "cswal_group_table";
+
+ /** Sequence for groups table. */
+ const groupSeq = "cswal_group_table_group_id_seq";
+
+ //============================================================================
+ public abstract function __construct(cs_phpDB $db) {
+ parent::__construct($db);
+ }//end __construct()
+ //============================================================================
+
+
+
+ //============================================================================
+ protected function clean_group_name($groupName) {
+ try {
+ $retval = $this->clean_permission_name($groupName);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to clean group name (". $groupName .")");
+ }
+ return($retval);
+ }//end clean_group_name()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_group($groupName) {
+ try {
+ $groupName = $this->clean_group_name($groupName);
+ $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $groupName ."')";
+ $newId = $this->db->run_insert($sql, self::groupSeq);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create group (". $groupName ."), DETAILS::: ". $e->getMessage());
+ }
+ return($newId);
+ }//end create_group()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_group($groupName) {
+ try {
+ $groupName = $this->clean_group_name($groupName);
+ $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $groupName ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to locate group (". $groupName ."), DETAILS::: ". $e->getMessage());
+ }
+ return($retval);
+ }//end get_group()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_group_by_id($groupId) {
+ try {
+ if(!is_null($groupId) && is_numeric($groupId)) {
+ $sql = "SELECT * FROM ". self::groupTable ." WHERE group_id='". $groupId ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid group ID (". $groupId .")");
+ }
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to locate group ID (". $groupId ."), DETAILS::: ". $e->getMessage());
+ }
+ return($retval);
+ }//end get_group_by_id()
+ //============================================================================
+
+}
+?>
Copied: trunk/0.3/abstract/cs_genericPermission.abstract.class.php (from rev 162, trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_genericPermission.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_genericPermission.abstract.class.php 2010-06-15 02:16:11 UTC (rev 168)
@@ -0,0 +1,122 @@
+<?php
+/*
+ * Created on June 03, 2010
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_genericPermissionAbstract extends cs_webapplibsAbstract {
+
+ /** Database object. */
+ public $db;
+
+ /** cs_globalFunctions object, for cleaning strings & such. */
+ public $gfObj;
+
+ /** Table name used to store permissions. */
+ const permTable = "cswal_permission_table";
+
+ /** Sequence for permissions table. */
+ const permSeq = "cswal_permission_table_permission_id";
+
+ //============================================================================
+ public abstract function __construct(cs_phpDB $db) {
+ $this->db = $db;
+ $this->gfObj = new cs_globalFunctions;
+ }//end __construct()
+ //============================================================================
+
+
+
+ //============================================================================
+ protected function clean_permission_name($name) {
+ if(!is_null($name) && is_string($name) && strlen($name)) {
+ $name = $this->gfObj->cleanString(strtolower($name), 'email');
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid string (". $name .")");
+ }
+ }//end clean_permission_name()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_permission($name) {
+ try{
+ $name = $this->clean_permission_name($name);
+ $sql = "INSERT INTO ". self::permTable ." (permission_name) VALUES ('". $name ."')";
+ $newId = $this->db->run_insert($sql, self::permSeq);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage());
+ }
+
+ return($newId);
+ }//end create_permission()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_permission($name) {
+ try {
+ $name = $this->clean_permission_name($name);
+ $sql = "SELECT * FROM ". self::permTable ." WHERE permission_name='". $name ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: error while locating permission '". $name ."', DETAILS::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end get_permission()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_permission_by_id($permId) {
+ try {
+ if(!is_null($permId) && is_numeric($permId)) {
+ $sql = "SELECT * FROM ". self::permTable ." WHERE permission_id='". $permId ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid permission ID (". $permId .")");
+ }
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: error while locating permission '". $permId ."', DETAILS::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end get_permission_by_id()
+ //============================================================================
+
+
+
+ //============================================================================
+ /**
+ * Build the schema for permissions.
+ */
+ private function build_schema() {
+ try {
+ $result = $this->db->run_sql_file(dirname(__FILE__) .'/../setup/genericPermissions.pgsql.sql');
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create schema, DETAILS::: ". $e->getMessage());
+ }
+ if($result !== true) {
+ throw new exception(__METHOD__ .":: failed to create schema (no details)");
+ }
+ }//end build_schema()
+ //============================================================================
+}
+?>
Copied: trunk/0.3/abstract/cs_genericPermissionGroup.abstract.class.php (from rev 162, trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_genericPermissionGroup.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_genericPermissionGroup.abstract.class.php 2010-06-15 02:16:11 UTC (rev 168)
@@ -0,0 +1,96 @@
+<?php
+
+/*
+ * Created on June 14, 2010
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_genericPermissionGroupAbstract extends cs_genericGroupAbstract {
+
+ /** Table name used to store permission groups. */
+ const permGroupTable = "cswal_permission_group_table";
+
+ /** Sequence for permission_group table. */
+ const groupSeq = "cswal_permission_group_table_permission_group_id_seq";
+
+ //============================================================================
+ public abstract function __construct(cs_phpDB $db) {
+ parent::__construct($db);
+ }//end __construct()
+ //============================================================================
+
+
+
+ //============================================================================
+ protected function clean_perm_group_name($permGroupName) {
+ try {
+ $retval = $this->clean_group_name($permGroupName);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to clean group name (". $groupName .")");
+ }
+ return($retval);
+ }//end clean_perm_group_name()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_group($groupName) {
+ try {
+ $groupName = $this->clean_group_name($groupName);
+ $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $groupName ."')";
+ $newId = $this->db->run_insert($sql, self::groupSeq);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create group (". $groupName ."), DETAILS::: ". $e->getMessage());
+ }
+ return($newId);
+ }//end create_group()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_group($groupName) {
+ try {
+ $groupName = $this->clean_group_name($groupName);
+ $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $groupName ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to locate group (". $groupName ."), DETAILS::: ". $e->getMessage());
+ }
+ return($retval);
+ }//end get_group()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_group_by_id($groupId) {
+ try {
+ if(!is_null($groupId) && is_numeric($groupId)) {
+ $sql = "SELECT * FROM ". self::groupTable ." WHERE group_id='". $groupId ."'";
+ $retval = $this->db->run_query($sql);
+ }
+ else {
+ throw new exception(__METHOD__ .":: invalid group ID (". $groupId .")");
+ }
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to locate group ID (". $groupId ."), DETAILS::: ". $e->getMessage());
+ }
+ return($retval);
+ }//end get_group_by_id()
+ //============================================================================
+
+}
+?>
Added: trunk/0.3/docs/example_genericPermission.php
===================================================================
--- trunk/0.3/docs/example_genericPermission.php (rev 0)
+++ trunk/0.3/docs/example_genericPermission.php 2010-06-15 02:16:11 UTC (rev 168)
@@ -0,0 +1,53 @@
+<?php
+
+//instantiate the permission object with a database & the proper UID.
+$permObj = new cs_genericUserPermission($page->db, $_SESSION['uid']);
+
+
+//Creating Permissions/Groups
+{
+ //create a group.
+ $permObj->create_group("blogs");
+
+ //define default permissions for the group.
+ //NOTE::: the "false" entries can be technically excluded, as the default is false.
+ $perms = array(
+ 'view' => true,
+ 'create' => true,
+ 'edit' => true,
+ 'set_timestamp' => true,
+ 'update_timestamp' => false,
+ 'delete_entry' => false,
+ 'set_draft' => true,
+ 'update_to_draft' => false
+ );
+ $permObj->set_group_perms("blogs", $perms);
+
+ //set specific permissions for a user.
+ //NOTE::: if the group or permission doesn't exist, this will throw an exception.
+ $permObj->set_user_perm("blogs", "update_timestamp");
+}
+
+
+//Checking Permissions/Groups
+{
+ //get a list of permissions...
+ $perms = $permObj->get_user_permissions();
+
+ //check if the user is part of a group... in this case, the "blogs" group.
+ $isGroupMember = $permObj->check_group_membership("blogs");
+
+ //Pull all available permissions for a group... again, the "blogs" group.
+ $allBlogsPerms = $permObj->get_group_perms("blogs");
+
+ //check permissions for a specific "group" (or "object")... in this case, "can the user create a blog?"
+ $hasPermission = $permObj->check_permission("blogs", "create");
+
+
+ //a more advanced check, involving membership in multiple cascading groups (unimplemented)... "can the user administratively view blogs?"
+ //NOTE::: the code in this method would have to allow an unlimited number of arguments (minimum 2), where the last one is the permission name.
+ #$permObj->check_cascading_permission("admin", "blogs", "view");
+}
+
+
+?>
Property changes on: trunk/0.3/docs/example_genericPermission.php
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/0.3/setup/genericPermissions.pgsql.sql
===================================================================
--- trunk/0.3/setup/genericPermissions.pgsql.sql (rev 0)
+++ trunk/0.3/setup/genericPermissions.pgsql.sql 2010-06-15 02:16:11 UTC (rev 168)
@@ -0,0 +1,58 @@
+
+--
+-- Permission table
+-- Specific permissions: these are words used by the code to determine if the user has the appropriate permission.
+--
+CREATE TABLE cswal_permission_table (
+ permission_id serial NOT NULL PRIMARY KEY,
+ permission_name text NOT NULL UNIQUE
+);
+
+
+--
+-- Group table
+-- Enumerates a list of permissions for a specific group: i.e. for "blog", this could list "create", "edit", and "delete" (among others).
+--
+CREATE TABLE cswal_group_table (
+ group_id serial NOT NULL PRIMARY KEY,
+ group_name text NOT NULL UNIQUE
+);
+
+--
+-- Permission + Group table
+-- Enumerates permissions for a given group: any permissions not specifically entered are denied.
+--
+CREATE TABLE cswal_permission_group_table (
+ permission_group_id serial NOT NULL PRIMARY KEY,
+ permission_id integer NOT NULL REFERENCES cswal_permission_table(permission_id),
+ group_id integer NOT NULL REFERENCES cswal_group_table(group_id),
+ allowed boolean NOT NULL DEFAULT false,
+ description text
+);
+
+--
+-- User + Group table
+-- Assigns a user to one or more groups.
+-- NOTE::: the "user_id" column should be (manually) foreign-keyed to an existing user table.
+--
+CREATE TABLE cswal_user_group_table (
+ user_group_id serial NOT NULL PRIMARY KEY,
+ user_id integer NOT NULL,
+ group_id integer NOT NULL REFERENCES cswal_group_table(group_id)
+);
+
+
+--
+-- User + Permission table
+-- Give users specific permissions, overriding default and/or assigned group permissions.
+--
+CREATE TABLE cswal_user_permission_table (
+ user_permission_id serial NOT NULL PRIMARY KEY,
+ user_id integer NOT NULL,
+ group_id integer NOT NULL REFERENCES cswal_group_table(group_id),
+ permission_id integer NOT NULL REFERENCES cswal_permission_table(permission_id),
+ allowed boolean NOT NULL DEFAULT false
+);
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-06-15 02:13:55
|
Revision: 167
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=167&view=rev
Author: crazedsanity
Date: 2010-06-15 02:13:49 +0000 (Tue, 15 Jun 2010)
Log Message:
-----------
Updated example upgrade.xml file.
Modified Paths:
--------------
trunk/0.3/upgrades/upgrade.xml
Modified: trunk/0.3/upgrades/upgrade.xml
===================================================================
--- trunk/0.3/upgrades/upgrade.xml 2010-06-15 02:12:26 UTC (rev 166)
+++ trunk/0.3/upgrades/upgrade.xml 2010-06-15 02:13:49 UTC (rev 167)
@@ -1,22 +1,37 @@
<upgrade>
- <system_note>To determine which section in matching to use, heed only the information
- beneath the tag that indicates the current database version (for 5.2.4,
- you would find information under matching for "v5.2.4"). This section
- indicates the version that it should upgrade the database to
- ("target_version"), the name of the script ("script_name"), the class name
- ("class_name"), and the name of the method within that class ("call_method")
- to call in order to perform the upgrade. The method should return TRUE on
- success: anything else would indicate failure. Upgrade failure may leave
- the system in an inconsistent state.
+ <system_note>To determine which section in matching to use, find the heading
+ that matches the version to upgrade FROM: i.e. if upgrading from v1.2.0-ALPHA3
+ to v1.2.0-ALPHA4, find the entry "v1.2.0-ALPHA3"; the "target_version" tag
+ beneath that entry indicates what the version will be afterward.
+ When building a script, the name of the file should be indicative of what it
+ will do, such as "upgradeTo1.2.0-ALPHA4.php". The class name should be
+ similar as well, but avoid dots and dashes; "upgrade_to_1_2_0_alpha4" would
+ be just fine. Generally I have the same method name ("call_method") for
+ performing the update, which may call other methods to get the job done.
+
IMPORTANT: in order to facilitate doing multiple version upgrades, the name
of the class must be UNIQUE to all the other classes. For this reason, the
- class name should be something like "v1_0_0_ALPHA1__to__v1_0_0_ALPHA2".
+ class name should be something like "upgrade_to_1_2_0_alpha4".
REMEMBER: the "target_version" should NEVER be higher than the next item
- beneath matching; this will cause horrible logic errors, causing an upgsrade
+ beneath matching; this will cause horrible logic errors, causing an upgrade
to get skipped, or an exception to be thrown, potentially leaving the system
in an unstable state. Unstable is bad, m'kay?</system_note>
- <matching />
+ <examples>
+ <v1.2.0-ALPHA3>
+ <target_version>1.2.0-ALPHA4</target_version>
+ <script_name>upgradeTo1.2.0-ALPHA4.php</script_name>
+ <class_name>upgrade_to_1_2_0_ALPHA4</class_name>
+ <call_method>run_upgrade</call_method>
+ </v1.2.0-ALPHA3>
+ <v1.2.0-ALPHA6>
+ <target_version>1.2.0-ALPHA7</target_version>
+ <script_name>upgradeTo1.2.0-ALPHA7.php</script_name>
+ <class_name>upgrade_to_1_2_0_ALPHA7</class_name>
+ <call_method>run_upgrade</call_method>
+ </v1.2.0-ALPHA6>
+ </examples>
+ <example_initialversion>0.1.0-BETA1</example_initialversion>
</upgrade>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-06-15 02:12:32
|
Revision: 166
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=166&view=rev
Author: crazedsanity
Date: 2010-06-15 02:12:26 +0000 (Tue, 15 Jun 2010)
Log Message:
-----------
Remove generic data linker.
Removed Paths:
-------------
trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php
trunk/0.3/abstract/cs_gdlObject.abstract.class.php
trunk/0.3/abstract/cs_gdlPath.abstract.class.php
trunk/0.3/cs_genericDataLinker.class.php
Deleted: trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php 2010-06-15 02:10:54 UTC (rev 165)
+++ trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php 2010-06-15 02:12:26 UTC (rev 166)
@@ -1,89 +0,0 @@
-<?php
-/*
- * Created on Jan 29, 2009
- *
- * FILE INFORMATION:
- *
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-abstract class cs_gdlAttribAbstract extends cs_gdlPathAbstract {
-
-
- const table='cswal_gdl_attribute_table';
- const tableSeq = 'cswal_gdl_attribute_table_attribute_id_seq';
-
-
-
- //-------------------------------------------------------------------------
- public function create_attrib($path, $data, $type=null) {
-
- $objectId = $this->get_object_id_from_path($path);
-
- $insertString = "";
- $attribs = array();
- if(is_array($data) && count($data)) {
- foreach($data as $n=>$v) {
- $n = $this->translate_attrib_name($n);
- $attribs[$n] = $v;
- }
- }
- elseif(!is_null($type)) {
- $key = $this->translate_attrib_name($type);
- $attribs = array($key => $data);
- }
- else {
- throw new exception(__METHOD__ .": data was not array and no type set");
- }
-
- if(!is_array($attribs) || !count($attribs)) {
- throw new exception(__METHOD__ .": failed to create an array of attributes... ". $this->gfObj->debug_print(func_get_args(),0));
- }
-
- $attribs['object_id'] = $objectId;
- $insertString = $this->gfObj->string_from_array($attribs, 'insert');
-
-
- if(!strlen($insertString)) {
- throw new exception(__METHOD__ .": invalid insert string (". $insertString .")");
- }
- $sql = "INSERT INTO ". self::attrTable ." ". $insertString;
-
- try {
- $retval = $this->db->run_insert($sql, self::attrTableSeq);
- }
- catch(exception $e) {
- throw new exception(__METHOD__ .": failed to perform insert::: ". $e->getMessage() .' ---- '. $sql);
- }
-
- return($retval);
- }//end create_attrib()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function translate_attrib_name($name) {
- $retval = null;
- foreach($this->validTypes as $type) {
- if(preg_match('/^'. $type .'/', $name)) {
- $retval = 'a_'. $type;
- break;
- }
- }
-
- if(is_null($retval) || !strlen($retval)) {
- $this->gfObj->debug_print(__METHOD__ .": name was (". $name ."), retval=(". $retval .")",1);
- throw new exception(__METHOD__ .": invalid attribute name (". $name .")");
- }
-
- return($retval);
- }//end translate_attrib_name()
- //-------------------------------------------------------------------------
-
-}
-?>
\ No newline at end of file
Deleted: trunk/0.3/abstract/cs_gdlObject.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_gdlObject.abstract.class.php 2010-06-15 02:10:54 UTC (rev 165)
+++ trunk/0.3/abstract/cs_gdlObject.abstract.class.php 2010-06-15 02:12:26 UTC (rev 166)
@@ -1,130 +0,0 @@
-<?php
-/*
- * Created on Jan 29, 2009
- *
- * FILE INFORMATION:
- *
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-abstract class cs_gdlObjectAbstract extends cs_webapplibsAbstract {
-
-
- const table='cswal_gdl_object_table';
- const tableSeq = 'cswal_gdl_object_table_object_id_seq';
-
- //-------------------------------------------------------------------------
- public function get_object_id_from_path($path) {
- $sql = "SELECT object_id FROM ". self::table ." WHERE object_path='".
- $this->clean_path($path) ."'";
-
- try {
- $data = $this->db->run_query($sql);
-
- if(is_array($data) && count($data) == 1) {
- $retval = $data['object_id'];
- }
- else {
- throw new exception(__METHOD__ .": invalid data for path (". $this->clean_path($path) .")::: ". $this->gfObj->debug_var_dump($data,0));
- }
- }
- catch(exception $e) {
- throw new exception(__METHOD__ .": error retrieving path::: ". $e->getMessage());
- }
-
- return($retval);
- }//end get_object_id_from_path()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function create_object($name, $data=null, $type=null) {
- $sql = "INSERT INTO ". self::table ." (object_name) VALUES ('".
- $this->gfObj->cleanString($this->clean_path($name), 'sql_insert') ."')";
- try {
- $retval = $this->db->run_insert($sql, self::tableSeq);
- }
- catch(exception $e) {
- throw new exception(__METHOD__ .": failed to perform insert::: ". $e->getMessage());
- }
-
- if(!is_null($data)) {
- throw new exception(__METHOD__ .": can't create data for objects yet");
- }
- return($retval);
- }//end create_object()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function build_object_id_list(array $objects) {
- $this->gfObj->switch_force_sql_quotes(1);
- $sql = "SELECT * FROM ". self::table ." WHERE object_name IN (".
- $this->gfObj->string_from_array($objects, null, ',', 'sql') .")";
- $this->gfObj->switch_force_sql_quotes(0);
-
- $retval = array();
- try {
- $retval = $this->db->run_query($sql, 'object_name', 'object_id');
- if(!is_array($retval)) {
- $retval = array();
- }
- }
- catch(exception $e) {
- //throw new exception(__METHOD__ .": failed to retrieve list");
- }
-
- return($retval);
- }//end build_object_id_list()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function build_object_name_list(array $objectIds) {
- $this->gfObj->switch_force_sql_quotes(1);
- $sql = "SELECT * FROM ". self::table ." WHERE object_id IN (".
- $this->gfObj->string_from_array($objectIds, null, ',', 'sql') .")";
- $this->gfObj->switch_force_sql_quotes(0);
-
- try {
- $retval = $this->db->run_query($sql, 'object_id', 'object_name');
- if(!is_array($retval)) {
- $retval = array();
- }
- }
- catch(exception $e) {
- throw new exception(__METHOD__ .": failed to retrieve list::: ". $e->getMessage());
- }
-
- return($retval);
- }//end build_object_id_list()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function create_objects_enmasse(array $objectList) {
- $retval = 0;
- foreach($objectList as $name) {
- try {
- $this->create_object($name);
- $retval++;
- }
- catch(exception $e) {
- //nothing to see here, move along.
- }
- }
- return($retval);
- }//end create_objects_enmasse()
- //-------------------------------------------------------------------------
-
-
-}
-?>
\ No newline at end of file
Deleted: trunk/0.3/abstract/cs_gdlPath.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_gdlPath.abstract.class.php 2010-06-15 02:10:54 UTC (rev 165)
+++ trunk/0.3/abstract/cs_gdlPath.abstract.class.php 2010-06-15 02:12:26 UTC (rev 166)
@@ -1,126 +0,0 @@
-<?php
-/*
- * Created on Jan 29, 2009
- *
- * FILE INFORMATION:
- *
- * $HeadURL$
- * $Id$
- * $LastChangedDate$
- * $LastChangedBy$
- * $LastChangedRevision$
- */
-
-abstract class cs_gdlPathAbstract extends cs_gdlObjectAbstract {
-
-
- const table='cswal_gdl_path_table';
- const tableSeq = 'cswal_gdl_path_table_path_id_seq';
-
-
-
-
-
- //-------------------------------------------------------------------------
- public function create_path($path) {
- $idList = $this->create_path_objects($path);
- $pathIdList = $this->create_id_path($idList);
-
- if($this->get_path_from_idlist($pathIdList)) {
- $retval = $pathIdList;
- }
- else {
-
- $sql = "INSERT INTO ". self::table ." (path_id_list) VALUES ('". $pathIdList ."')";
-
- try {
- $insertedId = $this->db->run_insert($sql, self::tableSeq);
- $retval = $pathIdList;
- }
- catch(exception $e) {
- throw new exception(__METHOD__ .": unable to create path::: ". $e->getMessage());
- }
- }
-
- return($retval);
- }//end create_path()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function clean_path($path, $appendBase=true) {
- if(strlen($path)) {
- if($appendBase === true && !is_null($this->basePath)) {
- $path = $this->basePath .'/'. $path;
- }
- $newPath = preg_replace('/\/{2,}/', '/', $path);
-
- if(!strlen($newPath)) {
- throw new exception(__METHOD__ .": new path is zero-length (". $newPath ."), old path=(". func_get_arg(0) .")");
- }
- }
- else {
- throw new exception(__METHOD__ .": no valid path given (". $path .")");
- }
-
- return($newPath);
- }//end clean_path()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function set_base_path($path) {
- if(is_null($path) || !strlen($path)) {
- $this->basePath = null;
- }
- else {
- $this->basePath = $this->clean_path($path,false);
- }
- }//end set_base_path()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function explode_path($path, $appendBase=true) {
- $path = $this->clean_path($path, $appendBase);
- $path = preg_replace('/^\//', '', $path);
- $path = preg_replace('/\/$/', '', $path);
-
- return(explode('/', $path));
- }//end explode_path()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function create_id_path(array $idList) {
- $retval = ':'. $this->gfObj->string_from_array($idList, null, '::') .':';
- return($retval);
- }//end create_id_path()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function get_path_from_idlist($idPath) {
-
- $idList = explode('::', preg_replace('/^:/', '', preg_replace('/:$/', '', $idPath)));
-
- $nameList = $this->build_object_name_list($idList);
-
- $retval = "/";
- foreach($nameList as $id=>$name) {
- $retval = $this->gfObj->create_list($retval, $name, '/');
- }
-
- $retval = $this->clean_path($retval,false);
-
- return($retval);
- }//end get_text_path_from_id_path()
- //-------------------------------------------------------------------------
-
-}
-?>
\ No newline at end of file
Deleted: trunk/0.3/cs_genericDataLinker.class.php
===================================================================
--- trunk/0.3/cs_genericDataLinker.class.php 2010-06-15 02:10:54 UTC (rev 165)
+++ trunk/0.3/cs_genericDataLinker.class.php 2010-06-15 02:12:26 UTC (rev 166)
@@ -1,101 +0,0 @@
-<?php
-/*
- * Created on Oct 27, 2009
- *
- * THE IDEA:::
- * 1.) Unix/Linux-like paths lead to an attribute.
- * 2.) Multiple paths can lead to the same attribute.
- * 3.) An attribute can be linked to its original path.
- * 4.) Each "directory" in a path is an object with an ID.
- * 5.) Paths themselves are only stored on attributes: intermediate paths may be valid if all objects
- * for that path are also valid (i.e. if "/one/two/three" is valid, so is "/two/one/three" and "/three/two/one").
- * 6.) Database...
- * a.) finding an attribute referencing a single object should be straightforward and fast.
- * b.) objects are unique to avoid excess duplicate pathways
- * c.) using id paths with each number wrapped in colons is simple (i.e. ":3342:", ":3342::3::3:"
- *
- * The idea here is to have a class that generically links data together (in a
- * database). It is not meant to be a super clean or speedy system, instead meant
- * as a way of describing relationships between various pieces of data.
- *
- * Once a path is created (list object_id's, separated by '::'), it should always have an attribute.
- *
- *
- * 1::2::3 -> select * from <bla> WHERE path = '2' OR path like '2::%' OR path like '%::2'
- * -OR-
- * :1::2::3: -> select * from <bla> WHERE path like '%:2:%'
- *
- * If an attribute is created with a small path (like "/test") and the id is 1, the attribute shows ":1:"
- * --> if the id is 7720218, then the attribute shows ":7720218:"
- *
- *
- * SVN INFORMATION:::
- * -------------------
- * Last Author::::::::: $Author$
- * Current Revision:::: $Revision$
- * Repository Location: $HeadURL$
- * Last Updated:::::::: $Date$
- */
-
-
-
-class cs_genericDataLinker extends cs_gdlAttribAbstract {
-
- const attrTable='cswal_gdl_attribute_table';
- const attrTableSeq='cswal_gdl_attribute_table_attribute_id_seq';
-
- protected $validTypes = array('text', 'int', 'dec', 'bool');
- protected $gfObj;
- protected $basePath=null;
-
- public $db;
-
- //-------------------------------------------------------------------------
- public function __construct(cs_phpDB $db) {
-
- parent::__construct($db);
- if(!$db->is_connected()) {
- throw new exception(__METHOD__ .": database not connected");
- }
- $this->db = $db;
- $this->gfObj = new cs_globalFunctions;
- }//end __construct()
- //-------------------------------------------------------------------------
-
-
-
- //-------------------------------------------------------------------------
- public function create_path_objects($path) {
- $newPath = $this->clean_path($path);
- $newPath = preg_replace('/^\//', '', $newPath);
-
- //break it into bits.
- $bits = explode('/', $newPath);
-
- $myList = $this->build_object_id_list($bits);
- if(count($myList) !== count($bits)) {
- $createThese = array();
- foreach($bits as $name) {
- if(!isset($myList[$name])) {
- $createThese[] = $name;
- }
- }
- $this->create_objects_enmasse($createThese);
- $myList = $this->build_object_id_list($bits);
- }
-
- $retval = array();
- foreach($bits as $name) {
- $retval[$name] = $myList[$name];
- }
-
- if(is_null($retval) || !is_array($retval) || !count($retval)) {
- throw new exception(__METHOD__ .": failed to build path objects... ". $retval);
- }
-
- return($retval);
- }//end create_path_objects()
- //-------------------------------------------------------------------------
-}
-
-?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-06-15 02:11:01
|
Revision: 165
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=165&view=rev
Author: crazedsanity
Date: 2010-06-15 02:10:54 +0000 (Tue, 15 Jun 2010)
Log Message:
-----------
Minor logic changes & ability to execute an entire SQL file.
/cs_phpDB.class.php:
* run_query():
-- shorten minimum SQL length to 15 (technically, valid SQL could be
shorter if it were calling a stored proc or "NOW()")
* run_sql_file() [NEW]:
-- execute the contents of an SQL file (for schema & such).
Modified Paths:
--------------
trunk/0.3/cs_phpDB.class.php
Modified: trunk/0.3/cs_phpDB.class.php
===================================================================
--- trunk/0.3/cs_phpDB.class.php 2010-06-15 02:07:39 UTC (rev 164)
+++ trunk/0.3/cs_phpDB.class.php 2010-06-15 02:10:54 UTC (rev 165)
@@ -93,8 +93,8 @@
$retval = array();
- //length must be 19 as that's about the shortest valid SQL: "select * from table"
- if(strlen($sql) >= 19) {
+ //length must be 15 as that's about the shortest valid SQL: "select * from x"
+ if(strlen($sql) >= 15) {
$this->exec($sql);
$numRows = $this->numRows();
@@ -187,6 +187,36 @@
}//end reconnect()
//=========================================================================
+
+ //=========================================================================
+ /**
+ * Execute the entire contents of the given file (with absolute path) as SQL.
+ */
+ public function run_sql_file($filename) {
+ if(!is_object($this->fsObj)) {
+ if(class_exists('cs_fileSystem')) {
+ $fsObj = new cs_fileSystem(dirname($filename));
+ }
+ else {
+ throw new exception(__METHOD__ .": required library (cs_fileSystem) not found");
+ }
+ }
+
+ $this->lastSQLFile = $filename;
+
+ $fileContents = $fsObj->read($filename);
+ try {
+ $this->db->run_update($fileContents, true);
+ $this->build_cache();
+ $retval = TRUE;
+ }
+ catch(exception $e) {
+ $retval = FALSE;
+ }
+
+ return($retval);
+ }//end run_sql_file()
+ //=========================================================================
} // end class phpDB
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-06-15 02:07:45
|
Revision: 164
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=164&view=rev
Author: crazedsanity
Date: 2010-06-15 02:07:39 +0000 (Tue, 15 Jun 2010)
Log Message:
-----------
Remove suspended logging, as the logger should be using a forcibly different connection (thus not subject to any transaction).
Modified Paths:
--------------
trunk/0.3/cs_webdbupgrade.class.php
Modified: trunk/0.3/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.3/cs_webdbupgrade.class.php 2010-06-09 01:25:09 UTC (rev 163)
+++ trunk/0.3/cs_webdbupgrade.class.php 2010-06-15 02:07:39 UTC (rev 164)
@@ -320,7 +320,6 @@
//=========================================================================
private function perform_upgrade() {
- $this->logsObj->suspendLogging=true;
//make sure there's not already a lockfile.
if($this->upgrade_in_progress()) {
//ew. Can't upgrade.
@@ -393,12 +392,9 @@
$this->error_handler(__METHOD__ .": transaction status=(". $transactionStatus ."), upgrade aborted:::". $e->getMessage());
$this->db->rollbackTrans();
}
- $this->logsObj->suspendLogging=false;
$this->do_log("Upgrade process complete", 'end');
}
}
- $this->logsObj->suspendLogging=false;
- $logsHandled = $this->logsObj->handle_suspended_logs();
}//end perform_upgrade()
//=========================================================================
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-06-09 01:25:16
|
Revision: 163
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=163&view=rev
Author: crazedsanity
Date: 2010-06-09 01:25:09 +0000 (Wed, 09 Jun 2010)
Log Message:
-----------
Remove logging when it cleans sessions.
Modified Paths:
--------------
trunk/0.3/cs_sessionDB.class.php
Modified: trunk/0.3/cs_sessionDB.class.php
===================================================================
--- trunk/0.3/cs_sessionDB.class.php 2010-05-27 14:49:12 UTC (rev 162)
+++ trunk/0.3/cs_sessionDB.class.php 2010-06-09 01:25:09 UTC (rev 163)
@@ -303,11 +303,11 @@
}
$numCleaned = $this->db->run_update($sql, true);
- if($numCleaned > 0) {
- $this->do_log("cleaned (". $numCleaned .") old sessions, " .
- "excludeCurrent=(". $this->gfObj->interpret_bool($excludeCurrent) .")" .
- ", maxFreshness=(". $maxFreshness .")", "debug");
- }
+ #if($numCleaned > 0) {
+ # $this->do_log("cleaned (". $numCleaned .") old sessions, " .
+ # "excludeCurrent=(". $this->gfObj->interpret_bool($excludeCurrent) .")" .
+ # ", maxFreshness=(". $maxFreshness .")", "debug");
+ #}
}
catch(exception $e) {
$this->exception_handler(__METHOD__ .": exception while cleaning: ". $e->getMessage());
@@ -350,4 +350,4 @@
}//end cs_session{}
-?>
\ No newline at end of file
+?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-05-27 14:49:18
|
Revision: 162
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=162&view=rev
Author: crazedsanity
Date: 2010-05-27 14:49:12 +0000 (Thu, 27 May 2010)
Log Message:
-----------
Ability to retrieve internal properties from cs_tabs{}.
/cs_tabs.class.php:
* __get() [NEW]:
-- ability to retrieve any (existing) internal property (easily allows
for page titles to be dynamically set to name of selected tab).
Modified Paths:
--------------
trunk/0.3/cs_tabs.class.php
Modified: trunk/0.3/cs_tabs.class.php
===================================================================
--- trunk/0.3/cs_tabs.class.php 2010-05-27 14:31:40 UTC (rev 161)
+++ trunk/0.3/cs_tabs.class.php 2010-05-27 14:49:12 UTC (rev 162)
@@ -184,5 +184,19 @@
}//end rename_tab();
//---------------------------------------------------------------------------------------------
+
+
+ //---------------------------------------------------------------------------------------------
+ public function __get($name) {
+ if(isset($this->$name)) {
+ $retval = $this->$name;
+ }
+ else {
+ throw new exception(__METHOD__ .": no such var (". $name .")");
+ }
+ return($retval);
+ }//end __get()
+ //---------------------------------------------------------------------------------------------
+
}
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-05-27 14:31:49
|
Revision: 161
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=161&view=rev
Author: crazedsanity
Date: 2010-05-27 14:31:40 +0000 (Thu, 27 May 2010)
Log Message:
-----------
Fix tab selection to be a bit more forgiving.
/cs_tabs.class.php:
* select_tab():
-- try to matching tabname to the beginning of each tabname or the
end of each url if the actual tab name given doesn't exist.
-- returns selected tab name.
Modified Paths:
--------------
trunk/0.3/cs_tabs.class.php
Modified: trunk/0.3/cs_tabs.class.php
===================================================================
--- trunk/0.3/cs_tabs.class.php 2010-05-13 18:16:07 UTC (rev 160)
+++ trunk/0.3/cs_tabs.class.php 2010-05-27 14:31:40 UTC (rev 161)
@@ -66,7 +66,22 @@
* @return (void)
*/
public function select_tab($tabName) {
- $this->selectedTab = $tabName;
+ $selected = $tabName;
+
+ if(!$this->tab_exists($tabName)) {
+ $fixedTabName = strtolower($tabName);
+ foreach($this->tabsArr as $name => $info) {
+ if(preg_match('/^'. $tabName .'/', $name)) {
+ $selected = $name;
+ }
+ elseif(preg_match('/'. $tabName .'$/', $info['url'])) {
+ $selected = $name;
+ }
+ }
+ }
+
+ $this->selectedTab = $selected;
+ return($this->selectedTab);
}//end select_tab()
//---------------------------------------------------------------------------------------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-05-13 18:16:16
|
Revision: 160
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=160&view=rev
Author: crazedsanity
Date: 2010-05-13 18:16:07 +0000 (Thu, 13 May 2010)
Log Message:
-----------
Stop passing some variables by reference to avoid some PHP errors (pass-by-reference isn't really supported like that anymore).
Modified Paths:
--------------
trunk/0.3/cs_siteConfig.class.php
trunk/0.3/cs_webdbupgrade.class.php
Modified: trunk/0.3/cs_siteConfig.class.php
===================================================================
--- trunk/0.3/cs_siteConfig.class.php 2010-03-09 19:08:59 UTC (rev 159)
+++ trunk/0.3/cs_siteConfig.class.php 2010-05-13 18:16:07 UTC (rev 160)
@@ -259,7 +259,7 @@
$this->isInitialized=true;
if(count($this->setGlobalArrays)) {
- $globA2p = new cs_arrayToPath(&$GLOBALS);
+ $globA2p = new cs_arrayToPath($GLOBALS);
foreach($this->setGlobalArrays as $configPath=>$globalsPath) {
if($this->a2p->get_data($configPath)) {
$setMe = array();
Modified: trunk/0.3/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.3/cs_webdbupgrade.class.php 2010-03-09 19:08:59 UTC (rev 159)
+++ trunk/0.3/cs_webdbupgrade.class.php 2010-05-13 18:16:07 UTC (rev 160)
@@ -858,7 +858,7 @@
$this->tempXmlConfig = array();
}
try {
- $myA2p = new cs_arrayToPath(&$this->tempXmlConfig);
+ $myA2p = new cs_arrayToPath($this->tempXmlConfig);
}
catch(exception $e) {
$this->do_log(__METHOD__ .': encountered exception: '. $e->getMessage());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2010-03-09 19:09:05
|
Revision: 159
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=159&view=rev
Author: crazedsanity
Date: 2010-03-09 19:08:59 +0000 (Tue, 09 Mar 2010)
Log Message:
-----------
Fix a potential recursion issue.
Modified Paths:
--------------
trunk/0.3/cs_webdbupgrade.class.php
Modified: trunk/0.3/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.3/cs_webdbupgrade.class.php 2009-11-17 01:54:40 UTC (rev 158)
+++ trunk/0.3/cs_webdbupgrade.class.php 2010-03-09 19:08:59 UTC (rev 159)
@@ -543,7 +543,9 @@
//add the table...
$loadTableResult = $this->load_table();
if($loadTableResult === TRUE) {
- $retval = $this->get_database_version();
+ //now try the SQL...
+ $numrows = $this->db->exec($sql);
+ $dberror = $this->db->errorMsg();
}
else {
$this->error_handler(__METHOD__ .": no table in database, failed to create one... ORIGINAL " .
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-11-17 01:54:49
|
Revision: 158
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=158&view=rev
Author: crazedsanity
Date: 2009-11-17 01:54:40 +0000 (Tue, 17 Nov 2009)
Log Message:
-----------
Fix situation where database version is not returned.
/cs_webdbupgrade.class.php:
* get_database_version():
-- calls itself if it has to load the database tables.
-- NOTE::: this could possibly cause an infinite loop or a deadlock
if loading the database tables is done incorrectly (though I am not
sure how to test for that scenario).
Modified Paths:
--------------
trunk/0.3/cs_webdbupgrade.class.php
Modified: trunk/0.3/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.3/cs_webdbupgrade.class.php 2009-11-09 18:48:26 UTC (rev 157)
+++ trunk/0.3/cs_webdbupgrade.class.php 2009-11-17 01:54:40 UTC (rev 158)
@@ -543,9 +543,7 @@
//add the table...
$loadTableResult = $this->load_table();
if($loadTableResult === TRUE) {
- //now try the SQL...
- $numrows = $this->db->exec($sql);
- $dberror = $this->db->errorMsg();
+ $retval = $this->get_database_version();
}
else {
$this->error_handler(__METHOD__ .": no table in database, failed to create one... ORIGINAL " .
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-11-09 18:48:36
|
Revision: 157
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=157&view=rev
Author: crazedsanity
Date: 2009-11-09 18:48:26 +0000 (Mon, 09 Nov 2009)
Log Message:
-----------
Minor changes.
/abstract/cs_gdlPath.abstract.class.php:
* create_path():
-- returns the pathIdList if available, otherwise creates the path.
* get_text_path_from_id_path() [RENAMED to get_path_from_idlist()]
* get_path_from_idlist() [NEW, RENAMED FROM get_text_path_from_id_path()]
-- removed call to debug_var_dump().
/setup/schema.pgsql.sql:
* make cswal_gdl_path_table.path_id_list UNIQUE.
/setup/schema.mysql.sql:
* make cswal_gdl_path_table.path_id_list UNIQUE.
/tests/testOfCSWebAppLibs.php:
* added more tests for get_path_from_idlist().
Modified Paths:
--------------
trunk/0.3/abstract/cs_gdlPath.abstract.class.php
trunk/0.3/setup/schema.mysql.sql
trunk/0.3/setup/schema.pgsql.sql
trunk/0.3/tests/testOfCSWebAppLibs.php
Modified: trunk/0.3/abstract/cs_gdlPath.abstract.class.php
===================================================================
--- trunk/0.3/abstract/cs_gdlPath.abstract.class.php 2009-11-09 17:25:37 UTC (rev 156)
+++ trunk/0.3/abstract/cs_gdlPath.abstract.class.php 2009-11-09 18:48:26 UTC (rev 157)
@@ -26,14 +26,20 @@
$idList = $this->create_path_objects($path);
$pathIdList = $this->create_id_path($idList);
- $sql = "INSERT INTO ". self::table ." (path_id_list) VALUES ('". $pathIdList ."')";
-
- try {
- $insertedId = $this->db->run_insert($sql, self::tableSeq);
+ if($this->get_path_from_idlist($pathIdList)) {
$retval = $pathIdList;
}
- catch(exception $e) {
- throw new exception(__METHOD__ .": unable to create path::: ". $e->getMessage());
+ else {
+
+ $sql = "INSERT INTO ". self::table ." (path_id_list) VALUES ('". $pathIdList ."')";
+
+ try {
+ $insertedId = $this->db->run_insert($sql, self::tableSeq);
+ $retval = $pathIdList;
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": unable to create path::: ". $e->getMessage());
+ }
}
return($retval);
@@ -99,12 +105,11 @@
//-------------------------------------------------------------------------
- public function get_text_path_from_id_path($idPath) {
+ public function get_path_from_idlist($idPath) {
$idList = explode('::', preg_replace('/^:/', '', preg_replace('/:$/', '', $idPath)));
$nameList = $this->build_object_name_list($idList);
- $this->gfObj->debug_var_dump($nameList,1);
$retval = "/";
foreach($nameList as $id=>$name) {
Modified: trunk/0.3/setup/schema.mysql.sql
===================================================================
--- trunk/0.3/setup/schema.mysql.sql 2009-11-09 17:25:37 UTC (rev 156)
+++ trunk/0.3/setup/schema.mysql.sql 2009-11-09 18:48:26 UTC (rev 157)
@@ -178,7 +178,7 @@
CREATE TABLE `cswal_gdl_path_table` (
`path_id` int(11) NOT NULL PRIMARY KEY auto_increment,
- `path_id_list` text NOT NULL
+ `path_id_list` text NOT NULL UNIQUE
) ENGINE=InnoDB;
--
Modified: trunk/0.3/setup/schema.pgsql.sql
===================================================================
--- trunk/0.3/setup/schema.pgsql.sql 2009-11-09 17:25:37 UTC (rev 156)
+++ trunk/0.3/setup/schema.pgsql.sql 2009-11-09 18:48:26 UTC (rev 157)
@@ -131,7 +131,7 @@
CREATE TABLE cswal_gdl_path_table (
path_id serial NOT NULL PRIMARY KEY,
- path_id_list text NOT NULL
+ path_id_list text NOT NULL UNIQUE
);
--
Modified: trunk/0.3/tests/testOfCSWebAppLibs.php
===================================================================
--- trunk/0.3/tests/testOfCSWebAppLibs.php 2009-11-09 17:25:37 UTC (rev 156)
+++ trunk/0.3/tests/testOfCSWebAppLibs.php 2009-11-09 18:48:26 UTC (rev 157)
@@ -244,6 +244,18 @@
$newPathIdList = $x->create_path('/testing/'. $myPath);
$myPathIdList = ':'. $this->gfObj->string_from_array(array_flip($pathBits), null, '::') .':';
$this->assertEqual($newPathIdList, $myPathIdList);
+
+ $this->assertEqual($newPathIdList, $x->create_path('/testing/'. $myPath));
+
+ $myRearrangedPath = array_reverse($pathBits, true);
+ $rPathIdList = ':'. $this->gfObj->string_from_array(array_flip($myRearrangedPath), null, '::') .':';
+ $rPath = '/'. $this->gfObj->string_from_array($myRearrangedPath, null, '/');
+ $this->assertEqual($x->create_path($rPath), $rPathIdList);
+
+ $this->assertEqual($x->get_path_from_idlist($x->create_path($rPath)), $x->get_path_from_idlist($rPathIdList));
+ $this->assertEqual($x->get_path_from_idlist($x->create_path($rPath)), $x->get_path_from_idlist($rPathIdList));
+ $this->assertEqual($x->get_path_from_idlist($x->create_path($rPath)), $x->get_path_from_idlist($rPathIdList));
+ $this->assertEqual($x->get_path_from_idlist($x->create_path($rPath)), $x->get_path_from_idlist($rPathIdList));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-11-09 17:25:47
|
Revision: 156
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=156&view=rev
Author: crazedsanity
Date: 2009-11-09 17:25:37 +0000 (Mon, 09 Nov 2009)
Log Message:
-----------
Fix possible PHP warning (if session doesn't exist).
Modified Paths:
--------------
trunk/0.3/cs_webdblogger.class.php
Modified: trunk/0.3/cs_webdblogger.class.php
===================================================================
--- trunk/0.3/cs_webdblogger.class.php 2009-10-29 03:28:38 UTC (rev 155)
+++ trunk/0.3/cs_webdblogger.class.php 2009-11-09 17:25:37 UTC (rev 156)
@@ -794,7 +794,7 @@
public function get_uid() {
$myUid = $this->defaultUid;
//check for a uid in the session.
- if(is_array($_SESSION) && isset($_SESSION['uid']) && is_numeric($_SESSION['uid'])) {
+ if(isset($_SESSION) && is_array($_SESSION) && isset($_SESSION['uid']) && is_numeric($_SESSION['uid'])) {
//got an ID in the session.
$myUid = $_SESSION['uid'];
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-10-29 03:28:46
|
Revision: 155
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=155&view=rev
Author: crazedsanity
Date: 2009-10-29 03:28:38 +0000 (Thu, 29 Oct 2009)
Log Message:
-----------
Initial work for a generic data linker (database-oriented).
NOTE::: mysql schema not checked for correctness.
Modified Paths:
--------------
trunk/0.3/setup/schema.mysql.sql
trunk/0.3/setup/schema.pgsql.sql
trunk/0.3/tests/testOfCSWebAppLibs.php
Added Paths:
-----------
trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php
trunk/0.3/abstract/cs_gdlObject.abstract.class.php
trunk/0.3/abstract/cs_gdlPath.abstract.class.php
trunk/0.3/cs_genericDataLinker.class.php
Copied: trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php (from rev 154, trunk/0.3/abstract/cs_phpDB.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_gdlAttrib.abstract.class.php 2009-10-29 03:28:38 UTC (rev 155)
@@ -0,0 +1,89 @@
+<?php
+/*
+ * Created on Jan 29, 2009
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_gdlAttribAbstract extends cs_gdlPathAbstract {
+
+
+ const table='cswal_gdl_attribute_table';
+ const tableSeq = 'cswal_gdl_attribute_table_attribute_id_seq';
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_attrib($path, $data, $type=null) {
+
+ $objectId = $this->get_object_id_from_path($path);
+
+ $insertString = "";
+ $attribs = array();
+ if(is_array($data) && count($data)) {
+ foreach($data as $n=>$v) {
+ $n = $this->translate_attrib_name($n);
+ $attribs[$n] = $v;
+ }
+ }
+ elseif(!is_null($type)) {
+ $key = $this->translate_attrib_name($type);
+ $attribs = array($key => $data);
+ }
+ else {
+ throw new exception(__METHOD__ .": data was not array and no type set");
+ }
+
+ if(!is_array($attribs) || !count($attribs)) {
+ throw new exception(__METHOD__ .": failed to create an array of attributes... ". $this->gfObj->debug_print(func_get_args(),0));
+ }
+
+ $attribs['object_id'] = $objectId;
+ $insertString = $this->gfObj->string_from_array($attribs, 'insert');
+
+
+ if(!strlen($insertString)) {
+ throw new exception(__METHOD__ .": invalid insert string (". $insertString .")");
+ }
+ $sql = "INSERT INTO ". self::attrTable ." ". $insertString;
+
+ try {
+ $retval = $this->db->run_insert($sql, self::attrTableSeq);
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": failed to perform insert::: ". $e->getMessage() .' ---- '. $sql);
+ }
+
+ return($retval);
+ }//end create_attrib()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function translate_attrib_name($name) {
+ $retval = null;
+ foreach($this->validTypes as $type) {
+ if(preg_match('/^'. $type .'/', $name)) {
+ $retval = 'a_'. $type;
+ break;
+ }
+ }
+
+ if(is_null($retval) || !strlen($retval)) {
+ $this->gfObj->debug_print(__METHOD__ .": name was (". $name ."), retval=(". $retval .")",1);
+ throw new exception(__METHOD__ .": invalid attribute name (". $name .")");
+ }
+
+ return($retval);
+ }//end translate_attrib_name()
+ //-------------------------------------------------------------------------
+
+}
+?>
\ No newline at end of file
Copied: trunk/0.3/abstract/cs_gdlObject.abstract.class.php (from rev 154, trunk/0.3/abstract/cs_phpDB.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_gdlObject.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_gdlObject.abstract.class.php 2009-10-29 03:28:38 UTC (rev 155)
@@ -0,0 +1,130 @@
+<?php
+/*
+ * Created on Jan 29, 2009
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_gdlObjectAbstract extends cs_webapplibsAbstract {
+
+
+ const table='cswal_gdl_object_table';
+ const tableSeq = 'cswal_gdl_object_table_object_id_seq';
+
+ //-------------------------------------------------------------------------
+ public function get_object_id_from_path($path) {
+ $sql = "SELECT object_id FROM ". self::table ." WHERE object_path='".
+ $this->clean_path($path) ."'";
+
+ try {
+ $data = $this->db->run_query($sql);
+
+ if(is_array($data) && count($data) == 1) {
+ $retval = $data['object_id'];
+ }
+ else {
+ throw new exception(__METHOD__ .": invalid data for path (". $this->clean_path($path) .")::: ". $this->gfObj->debug_var_dump($data,0));
+ }
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": error retrieving path::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end get_object_id_from_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_object($name, $data=null, $type=null) {
+ $sql = "INSERT INTO ". self::table ." (object_name) VALUES ('".
+ $this->gfObj->cleanString($this->clean_path($name), 'sql_insert') ."')";
+ try {
+ $retval = $this->db->run_insert($sql, self::tableSeq);
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": failed to perform insert::: ". $e->getMessage());
+ }
+
+ if(!is_null($data)) {
+ throw new exception(__METHOD__ .": can't create data for objects yet");
+ }
+ return($retval);
+ }//end create_object()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function build_object_id_list(array $objects) {
+ $this->gfObj->switch_force_sql_quotes(1);
+ $sql = "SELECT * FROM ". self::table ." WHERE object_name IN (".
+ $this->gfObj->string_from_array($objects, null, ',', 'sql') .")";
+ $this->gfObj->switch_force_sql_quotes(0);
+
+ $retval = array();
+ try {
+ $retval = $this->db->run_query($sql, 'object_name', 'object_id');
+ if(!is_array($retval)) {
+ $retval = array();
+ }
+ }
+ catch(exception $e) {
+ //throw new exception(__METHOD__ .": failed to retrieve list");
+ }
+
+ return($retval);
+ }//end build_object_id_list()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function build_object_name_list(array $objectIds) {
+ $this->gfObj->switch_force_sql_quotes(1);
+ $sql = "SELECT * FROM ". self::table ." WHERE object_id IN (".
+ $this->gfObj->string_from_array($objectIds, null, ',', 'sql') .")";
+ $this->gfObj->switch_force_sql_quotes(0);
+
+ try {
+ $retval = $this->db->run_query($sql, 'object_id', 'object_name');
+ if(!is_array($retval)) {
+ $retval = array();
+ }
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": failed to retrieve list::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end build_object_id_list()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_objects_enmasse(array $objectList) {
+ $retval = 0;
+ foreach($objectList as $name) {
+ try {
+ $this->create_object($name);
+ $retval++;
+ }
+ catch(exception $e) {
+ //nothing to see here, move along.
+ }
+ }
+ return($retval);
+ }//end create_objects_enmasse()
+ //-------------------------------------------------------------------------
+
+
+}
+?>
\ No newline at end of file
Copied: trunk/0.3/abstract/cs_gdlPath.abstract.class.php (from rev 154, trunk/0.3/abstract/cs_phpDB.abstract.class.php)
===================================================================
--- trunk/0.3/abstract/cs_gdlPath.abstract.class.php (rev 0)
+++ trunk/0.3/abstract/cs_gdlPath.abstract.class.php 2009-10-29 03:28:38 UTC (rev 155)
@@ -0,0 +1,121 @@
+<?php
+/*
+ * Created on Jan 29, 2009
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_gdlPathAbstract extends cs_gdlObjectAbstract {
+
+
+ const table='cswal_gdl_path_table';
+ const tableSeq = 'cswal_gdl_path_table_path_id_seq';
+
+
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_path($path) {
+ $idList = $this->create_path_objects($path);
+ $pathIdList = $this->create_id_path($idList);
+
+ $sql = "INSERT INTO ". self::table ." (path_id_list) VALUES ('". $pathIdList ."')";
+
+ try {
+ $insertedId = $this->db->run_insert($sql, self::tableSeq);
+ $retval = $pathIdList;
+ }
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": unable to create path::: ". $e->getMessage());
+ }
+
+ return($retval);
+ }//end create_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function clean_path($path, $appendBase=true) {
+ if(strlen($path)) {
+ if($appendBase === true && !is_null($this->basePath)) {
+ $path = $this->basePath .'/'. $path;
+ }
+ $newPath = preg_replace('/\/{2,}/', '/', $path);
+
+ if(!strlen($newPath)) {
+ throw new exception(__METHOD__ .": new path is zero-length (". $newPath ."), old path=(". func_get_arg(0) .")");
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": no valid path given (". $path .")");
+ }
+
+ return($newPath);
+ }//end clean_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function set_base_path($path) {
+ if(is_null($path) || !strlen($path)) {
+ $this->basePath = null;
+ }
+ else {
+ $this->basePath = $this->clean_path($path,false);
+ }
+ }//end set_base_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function explode_path($path, $appendBase=true) {
+ $path = $this->clean_path($path, $appendBase);
+ $path = preg_replace('/^\//', '', $path);
+ $path = preg_replace('/\/$/', '', $path);
+
+ return(explode('/', $path));
+ }//end explode_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_id_path(array $idList) {
+ $retval = ':'. $this->gfObj->string_from_array($idList, null, '::') .':';
+ return($retval);
+ }//end create_id_path()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function get_text_path_from_id_path($idPath) {
+
+ $idList = explode('::', preg_replace('/^:/', '', preg_replace('/:$/', '', $idPath)));
+
+ $nameList = $this->build_object_name_list($idList);
+ $this->gfObj->debug_var_dump($nameList,1);
+
+ $retval = "/";
+ foreach($nameList as $id=>$name) {
+ $retval = $this->gfObj->create_list($retval, $name, '/');
+ }
+
+ $retval = $this->clean_path($retval,false);
+
+ return($retval);
+ }//end get_text_path_from_id_path()
+ //-------------------------------------------------------------------------
+
+}
+?>
\ No newline at end of file
Added: trunk/0.3/cs_genericDataLinker.class.php
===================================================================
--- trunk/0.3/cs_genericDataLinker.class.php (rev 0)
+++ trunk/0.3/cs_genericDataLinker.class.php 2009-10-29 03:28:38 UTC (rev 155)
@@ -0,0 +1,101 @@
+<?php
+/*
+ * Created on Oct 27, 2009
+ *
+ * THE IDEA:::
+ * 1.) Unix/Linux-like paths lead to an attribute.
+ * 2.) Multiple paths can lead to the same attribute.
+ * 3.) An attribute can be linked to its original path.
+ * 4.) Each "directory" in a path is an object with an ID.
+ * 5.) Paths themselves are only stored on attributes: intermediate paths may be valid if all objects
+ * for that path are also valid (i.e. if "/one/two/three" is valid, so is "/two/one/three" and "/three/two/one").
+ * 6.) Database...
+ * a.) finding an attribute referencing a single object should be straightforward and fast.
+ * b.) objects are unique to avoid excess duplicate pathways
+ * c.) using id paths with each number wrapped in colons is simple (i.e. ":3342:", ":3342::3::3:"
+ *
+ * The idea here is to have a class that generically links data together (in a
+ * database). It is not meant to be a super clean or speedy system, instead meant
+ * as a way of describing relationships between various pieces of data.
+ *
+ * Once a path is created (list object_id's, separated by '::'), it should always have an attribute.
+ *
+ *
+ * 1::2::3 -> select * from <bla> WHERE path = '2' OR path like '2::%' OR path like '%::2'
+ * -OR-
+ * :1::2::3: -> select * from <bla> WHERE path like '%:2:%'
+ *
+ * If an attribute is created with a small path (like "/test") and the id is 1, the attribute shows ":1:"
+ * --> if the id is 7720218, then the attribute shows ":7720218:"
+ *
+ *
+ * SVN INFORMATION:::
+ * -------------------
+ * Last Author::::::::: $Author$
+ * Current Revision:::: $Revision$
+ * Repository Location: $HeadURL$
+ * Last Updated:::::::: $Date$
+ */
+
+
+
+class cs_genericDataLinker extends cs_gdlAttribAbstract {
+
+ const attrTable='cswal_gdl_attribute_table';
+ const attrTableSeq='cswal_gdl_attribute_table_attribute_id_seq';
+
+ protected $validTypes = array('text', 'int', 'dec', 'bool');
+ protected $gfObj;
+ protected $basePath=null;
+
+ public $db;
+
+ //-------------------------------------------------------------------------
+ public function __construct(cs_phpDB $db) {
+
+ parent::__construct($db);
+ if(!$db->is_connected()) {
+ throw new exception(__METHOD__ .": database not connected");
+ }
+ $this->db = $db;
+ $this->gfObj = new cs_globalFunctions;
+ }//end __construct()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function create_path_objects($path) {
+ $newPath = $this->clean_path($path);
+ $newPath = preg_replace('/^\//', '', $newPath);
+
+ //break it into bits.
+ $bits = explode('/', $newPath);
+
+ $myList = $this->build_object_id_list($bits);
+ if(count($myList) !== count($bits)) {
+ $createThese = array();
+ foreach($bits as $name) {
+ if(!isset($myList[$name])) {
+ $createThese[] = $name;
+ }
+ }
+ $this->create_objects_enmasse($createThese);
+ $myList = $this->build_object_id_list($bits);
+ }
+
+ $retval = array();
+ foreach($bits as $name) {
+ $retval[$name] = $myList[$name];
+ }
+
+ if(is_null($retval) || !is_array($retval) || !count($retval)) {
+ throw new exception(__METHOD__ .": failed to build path objects... ". $retval);
+ }
+
+ return($retval);
+ }//end create_path_objects()
+ //-------------------------------------------------------------------------
+}
+
+?>
Property changes on: trunk/0.3/cs_genericDataLinker.class.php
___________________________________________________________________
Added: svn:keywords
+ Author
Revision
HeadURL
Date
Modified: trunk/0.3/setup/schema.mysql.sql
===================================================================
--- trunk/0.3/setup/schema.mysql.sql 2009-09-29 16:12:49 UTC (rev 154)
+++ trunk/0.3/setup/schema.mysql.sql 2009-10-29 03:28:38 UTC (rev 155)
@@ -166,7 +166,35 @@
UNIQUE KEY `project_name` (`project_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
--
+-- Table for cs_genericDataLinker{}.
+--
+CREATE TABLE `cswal_gdl_object_table` (
+ `object_id` int(11) NOT NULL PRIMARY KEY auto_increment,
+ `object_name` text NOT NULL UNIQUE
+) ENGINE=InnoDB;
+
+
+CREATE TABLE `cswal_gdl_path_table` (
+ `path_id` int(11) NOT NULL PRIMARY KEY auto_increment,
+ `path_id_list` text NOT NULL
+) ENGINE=InnoDB;
+
+--
+-- Store attributes here.
+-- NOTE: fields prefixed with "a_" to avoid clashes with reserved words.
+--
+CREATE TABLE `cswal_gdl_attribute_table` (
+ `attribute_id` serial NOT NULL PRIMARY KEY auto_increment,
+ `object_path` text NOT NULL,
+ `a_text` text DEFAULT NULL,
+ `a_int` integer DEFAULT NULL,
+ `a_dec` decimal(10,2) DEFAULT NULL,
+ `a_bool` boolean DEFAULT NULL
+) ENGINE=InnoDB;
+
+--
-- Constraints for dumped tables
--
Modified: trunk/0.3/setup/schema.pgsql.sql
===================================================================
--- trunk/0.3/setup/schema.pgsql.sql 2009-09-29 16:12:49 UTC (rev 154)
+++ trunk/0.3/setup/schema.pgsql.sql 2009-10-29 03:28:38 UTC (rev 155)
@@ -120,3 +120,29 @@
);
+--
+-- Table for cs_genericDataLinker{}.
+--
+CREATE TABLE cswal_gdl_object_table (
+ object_id serial NOT NULL PRIMARY KEY,
+ object_name text NOT NULL UNIQUE
+);
+
+
+CREATE TABLE cswal_gdl_path_table (
+ path_id serial NOT NULL PRIMARY KEY,
+ path_id_list text NOT NULL
+);
+
+--
+-- Store attributes here.
+-- NOTE: fields prefixed with "a_" to avoid clashes with reserved words.
+--
+CREATE TABLE cswal_gdl_attribute_table (
+ attribute_id serial NOT NULL PRIMARY KEY,
+ object_path text NOT NULL,
+ a_text text DEFAULT NULL,
+ a_int integer DEFAULT NULL,
+ a_dec decimal(10,2) DEFAULT NULL,
+ a_bool boolean DEFAULT NULL
+);
Modified: trunk/0.3/tests/testOfCSWebAppLibs.php
===================================================================
--- trunk/0.3/tests/testOfCSWebAppLibs.php 2009-09-29 16:12:49 UTC (rev 154)
+++ trunk/0.3/tests/testOfCSWebAppLibs.php 2009-10-29 03:28:38 UTC (rev 155)
@@ -11,13 +11,15 @@
* $LastChangedRevision$
*/
-
class testOfCSWebAppLibs extends UnitTestCase {
//--------------------------------------------------------------------------
function __construct() {
$this->gfObj = new cs_globalFunctions;
$this->gfObj->debugPrintOpt=1;
+ if(!defined('CS_UNITTEST')) {
+ throw new exception(__METHOD__ .": FATAL: constant 'CS_UNITTEST' not set, can't do testing safely");
+ }
}//end __construct()
//--------------------------------------------------------------------------
@@ -45,7 +47,8 @@
$tableList = array(
'cswal_auth_token_table', 'cswal_version_table', 'cswal_attribute_table',
'cswal_category_table', 'cswal_class_table', 'cswal_event_table',
- 'cswal_log_attribute_table', 'cswal_log_table', 'cswal_session_store_table'
+ 'cswal_log_attribute_table', 'cswal_log_table', 'cswal_session_store_table',
+ 'cswal_gdl_object_table', 'cswal_gdl_attribute_table', 'cswal_gdl_path_table'
);
$db = $this->create_dbconn();
@@ -199,6 +202,250 @@
//--------------------------------------------------------------------------
+ function test_genericDataLinker() {
+
+ $x = new gdlTester($this->create_dbconn());
+
+ //test objects & paths first.
+ {
+ $myPath = '/character/sheet///Tetra Tealeaf';
+
+ $this->assertEqual(array('character', 'sheet', 'Tetra Tealeaf'), $x->explode_path($myPath));
+ $x->set_base_path('/testing');
+ $this->assertEqual('/testing/character/sheet/Tetra Tealeaf', $x->clean_path($myPath));
+ $this->assertEqual(array('testing', 'character', 'sheet', 'Tetra Tealeaf'), $x->explode_path($myPath));
+ $x->set_base_path(null);
+ $this->assertNotEqual(array('testing', 'character', 'sheet', 'Tetra Tealeaf'), $x->explode_path($myPath));
+ $this->assertEqual(array('character', 'sheet', 'Tetra Tealeaf'), $x->explode_path($myPath));
+ $this->assertEqual('/character/sheet/Tetra Tealeaf', $x->clean_path($myPath));
+
+ //now create some objects.
+ $pathBits = array();
+ foreach($x->explode_path($myPath) as $name) {
+ $pathBits[$x->create_object($name)] = $name;
+ }
+ $newPathIdList = $x->create_path($myPath);
+ $myPathIdList = ':'. $this->gfObj->string_from_array(array_keys($pathBits), null, '::') .':';
+ $this->assertEqual($newPathIdList, $myPathIdList);
+
+ $newId = $x->create_object('testing');
+ $t = array_keys($pathBits);
+ $t = array_pop($t);
+ $lastPathId = $t;
+ $this->assertEqual($newId, ($lastPathId +1));
+
+ $oldBits = $pathBits;
+ $pathBits = array();
+ $pathBits[$newId] = 'testing';
+ foreach($oldBits as $id=>$name) {
+ $pathBits[$id] = $name;
+ }
+
+ $newPathIdList = $x->create_path('/testing/'. $myPath);
+ $myPathIdList = ':'. $this->gfObj->string_from_array(array_flip($pathBits), null, '::') .':';
+ $this->assertEqual($newPathIdList, $myPathIdList);
+ }
+
+
+ /*/basic tests for building text-based paths vs. id-based paths.
+ {
+ $myPath = '/character/sheet/Tetra Tealeaf';
+
+
+ $idList = $x->createPathObjects($myPath);
+
+ $testObjectIdList = explode('/', preg_replace('/^\//', '', $myPath));
+ $this->assertEqual($idList, $x->build_object_id_list($testObjectIdList));
+
+ $idList2 = $x->create_path($myPath);
+ $this->assertEqual($x->create_id_path(array_values($idList)), $idList2);
+
+ $this->assertEqual($myPath, $x->get_text_path_from_id_path($x->create_id_path($idList)));
+ $this->gfObj->debug_var_dump($x->get_text_path_from_id_path($x->create_id_path($idList)));
+
+ $this->gfObj->debug_var_dump($idList);
+ $this->gfObj->debug_var_dump($idList2);
+
+ $this->assertEqual(':1::2::3:', $idList2);
+ $this->assertEqual($idList2, ':'. $this->gfObj->string_from_array($idList, null, '::') .':');
+
+ $this->assertEqual(':1::2::3:', $x->create_id_path($idList));
+
+ $this->assertEqual(':1:', $x->create_id_path(array(1)));
+ $this->assertEqual(':000010:', $x->create_id_path(array('000010')));
+
+ }
+
+
+ // now REALLY test paths.
+ {
+ #$gdl = new gdlTester($this->create_dbconn());
+
+ $myBasePath = '/character/sheet/Xander Cage';
+ $x->set_base_path($myBasePath);
+
+ //now add something that should be BENEATH that path.
+ $idList = $x->create_path('attributes/str');
+
+ $this->gfObj->debug_var_dump($idList);
+ }
+ #*/
+
+
+
+
+ /*/test some basics first.
+ $translations = array(
+ 'good' => array(
+ 'a_int' => array('int', 'integer', 'integraIsACarNotAnArgument'),
+ 'a_dec' => array('dec', 'decimal', 'decemberIsAMonth'),
+ 'a_bool' => array('bool', 'boolean', 'boolJustLooksLikeSomethingJiggly'),
+ 'a_text' => array('text', 'textual', 'textPaperJustLooksPink')
+ ),
+ 'bad' => array(
+ 'a_int' => array('num', 'a_int', 'nittedStuff'),
+ 'a_dec' => array('dce', 'a_dec', 'dceStuff'),
+ 'a_bool' => array('bolo', 'a_bool', 'boloMeansBeOnLookOut'),
+ 'a_text' => array('txt', 'a_text', 'txtIsABadAbbreviation')
+ )
+ );
+
+ foreach($translations as $goodBad=>$matchesArray) {
+ foreach($matchesArray as $matchThis => $tryThese) {
+ foreach($tryThese as $k) {
+ try {
+ $this->assertEqual($matchThis, $x->translate_attrib_name($k));
+ }
+ catch(exception $e) {
+ if($goodBad == 'good') {
+ $this->assertFalse(true, "test (". $k .") should have been good, but was bad::: ". $e->getMessage());
+ }
+ }
+ }
+ }
+ }
+ $testData = array(
+ 'skills/Appraise/cc' => array('bool' => true),
+ 'skills/Appraise/mod' => array('int' => 3),
+ 'skills/Appraise/ab_mod' => array('int' => 3),
+ 'skills/Appraise/rank' => array('int' => 3),
+ 'skills/Appraise/misc_mod' => array('int' => 3),
+ 'skills/Appraise/notes' => array('text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit."),
+ 'skills/Appraise/test' => array(
+ 'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+ 'bool' => true,
+ 'dec' => 0.03
+ ),
+ );
+
+
+ $myBasePath = '/characters/Tetra Tealeaf/';
+ $x->set_base_path($myBasePath);
+ foreach($testData as $path=>$subData) {
+ $this->assertEqual($myBasePath . $path, $x->clean_path($path));
+ $this->assertTrue(is_numeric($x->create_object($path, $subData)));
+ }
+
+ //get each individual item about the skill 'Appraise' individually.
+ $x->get_object_attribs('skills/Appraise/cc', 'bool');
+ $x->get_object_attribs('skills/Appraise/mod', 'int');
+ $x->get_object_attribs('skills/Appraise/ab_mod', 'int');
+ $x->get_object_attribs('skills/Appraise/rank', 'int');
+ $x->get_object_attribs('skills/Appraise/misc_mod', 'int');
+ $x->get_object_attribs('skills/Appraise/notes', 'text');
+ $x->get_object_attribs('skills/Appraise/test', array('text', 'bool', 'dec'));
+ $returnVal = array(
+ 'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+ 'bool' => true,
+ 'dec' => 0.03
+ );
+
+
+ //another way to retrieve it, without caring about what types are returned:::
+ $returnVal = $x->get_all_object_attribs('skills/Appraise', false);
+ $returnVal = array(
+ 'cc' => array(
+ 'test' => null,
+ 'bool' => true,
+ 'int' => null,
+ 'dec' => null
+ ),
+ 'mod' => array(
+ 'test' => null,
+ 'bool' => null,
+ 'int' => 10,
+ 'dec' => null
+ ),
+ 'ab_mod' => array(
+ 'test' => null,
+ 'bool' => null,
+ 'int' => 3,
+ 'dec' => null
+ ),
+ 'rank' => array(
+ 'test' => null,
+ 'bool' => null,
+ 'int' => 6,
+ 'dec' => null
+ ),
+ 'misc_mod' => array(
+ 'test' => null,
+ 'bool' => null,
+ 'int' => 1,
+ 'dec' => null
+ ),
+ 'notes' => array(
+ 'test' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+ 'bool' => null,
+ 'int' => null,
+ 'dec' => null
+ ),
+ 'test' => array(
+ 'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+ 'bool' => true,
+ 'int' => null,
+ 'dec' => 0.03
+ )
+ );
+
+ //a better way to retrieve that data:
+ $returnVal = $x->get_all_object_attribs('skills/Appraise', false);
+ $returnVal = array(
+ 'cc' => true,
+ 'mod' => 10,
+ 'ab_mod' => 3,
+ 'rank' => 6,
+ 'misc_mod' => 1,
+ 'notes' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+ 'test' => array(
+ 'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+ 'bool' => true,
+ 'dec' => 0.03
+ )
+ );
+
+ //if we don't want all that junk in test, we can specify what to get for EACH one:
+ $types = array(
+ 'cc' => "bool",
+ 'test' => "dec"
+ );
+ $returnVal = $x->get_all_object_attribs('skills/Appraise', false, $types);
+ $returnVal = array(
+ 'cc' => true,
+ 'mod' => 10,
+ 'ab_mod' => 3,
+ 'rank' => 6,
+ 'misc_mod' => 1,
+ 'notes' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+ 'test' => 0.03
+ );
+ #*/
+ }//end test_genericDataLinker()
+ //--------------------------------------------------------------------------
+
+
+
+ //--------------------------------------------------------------------------
private function do_tokenTest(array $tokenData, $uid, $checksum) {
if($this->assertTrue(is_array($tokenData)) && $this->assertTrue(is_numeric($uid)) && $this->assertTrue(strlen($checksum))) {
@@ -213,6 +460,7 @@
}//end do_tokenTest()
//--------------------------------------------------------------------------
+
}
@@ -226,4 +474,17 @@
return($this->create_hash_string($tokenId, $uid, $checksum, $hash));
}
}
+
+class gdlTester extends cs_genericDataLinker {
+ public $isTest = true;
+
+ public function __construct($db) {
+ parent::__construct($db);
+ }
+
+ public function createPathObjects($path) {
+ return($this->create_path_objects($path));
+ }
+}
+
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-09-29 16:12:57
|
Revision: 154
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=154&view=rev
Author: crazedsanity
Date: 2009-09-29 16:12:49 +0000 (Tue, 29 Sep 2009)
Log Message:
-----------
Pass database parameters to webdblogger from database object.
/cs_webdblogger.class.php:
* __construct():
-- when $checkForUpgrades is true, pass $db->connectParams to the call
for creating a new cs_webdbupgrade{} object.
Modified Paths:
--------------
trunk/0.3/cs_webdblogger.class.php
Modified: trunk/0.3/cs_webdblogger.class.php
===================================================================
--- trunk/0.3/cs_webdblogger.class.php 2009-09-21 15:52:46 UTC (rev 153)
+++ trunk/0.3/cs_webdblogger.class.php 2009-09-29 16:12:49 UTC (rev 154)
@@ -102,7 +102,7 @@
//see if there's an upgrade to perform...
if($checkForUpgrades === true) {
$this->suspendLogging = true;
- $upgObj = new cs_webdbupgrade(dirname(__FILE__) . '/VERSION', dirname(__FILE__) .'/upgrades/upgrade.xml');
+ $upgObj = new cs_webdbupgrade(dirname(__FILE__) . '/VERSION', dirname(__FILE__) .'/upgrades/upgrade.xml', $db->connectParams);
$upgObj->check_versions(true);
$this->suspendLogging = false;
$this->handle_suspended_logs();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-09-21 15:52:58
|
Revision: 153
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=153&view=rev
Author: crazedsanity
Date: 2009-09-21 15:52:46 +0000 (Mon, 21 Sep 2009)
Log Message:
-----------
Set version file location in cs_webdbupgrade::__construct() to avoid errors.
Modified Paths:
--------------
trunk/0.3/cs_webdbupgrade.class.php
Modified: trunk/0.3/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.3/cs_webdbupgrade.class.php 2009-09-21 15:51:40 UTC (rev 152)
+++ trunk/0.3/cs_webdbupgrade.class.php 2009-09-21 15:52:46 UTC (rev 153)
@@ -69,6 +69,7 @@
public function __construct($versionFileLocation, $upgradeConfigFile, array $dbParams=null, $lockFile='upgrade.lock') {
//setup configuration parameters for database connectivity.
+ $this->set_version_file_location(dirname(__FILE__) .'/VERSION');
if(!is_array($dbParams) || !count($dbParams)) {
$prefix = preg_replace('/-/', '_', $this->get_project());
$dbParams = array(
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-09-21 15:51:50
|
Revision: 152
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=152&view=rev
Author: crazedsanity
Date: 2009-09-21 15:51:40 +0000 (Mon, 21 Sep 2009)
Log Message:
-----------
Remove debug_print() statement in beginTrans() for pgsql layer.
Modified Paths:
--------------
trunk/0.3/db_types/cs_phpDB__pgsql.class.php
Modified: trunk/0.3/db_types/cs_phpDB__pgsql.class.php
===================================================================
--- trunk/0.3/db_types/cs_phpDB__pgsql.class.php 2009-09-21 15:25:00 UTC (rev 151)
+++ trunk/0.3/db_types/cs_phpDB__pgsql.class.php 2009-09-21 15:51:40 UTC (rev 152)
@@ -783,7 +783,6 @@
$transLevel = $this->get_transaction_level();
//transaction started without using beginTrans()...
$this->transactionTree = array();
- $this->gfObj->debug_print(__METHOD__ .": transaction already started, transStatus=(". $transStatus ."), transLevel=(". $transLevel .")");
$this->transactionTree[] = "Already started...";
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-09-21 15:25:08
|
Revision: 151
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=151&view=rev
Author: crazedsanity
Date: 2009-09-21 15:25:00 +0000 (Mon, 21 Sep 2009)
Log Message:
-----------
Fix invalid RWDIR setting.
/cs_webdbupgrade.class.php:
* move creation of cs_fileSystem{} down lower
* set default rwDir to be TWO levels below the current file...
* create cs_fileSystem{} using constant SITE_ROOT
Modified Paths:
--------------
trunk/0.3/cs_webdbupgrade.class.php
Modified: trunk/0.3/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.3/cs_webdbupgrade.class.php 2009-09-21 04:40:36 UTC (rev 150)
+++ trunk/0.3/cs_webdbupgrade.class.php 2009-09-21 15:25:00 UTC (rev 151)
@@ -90,7 +90,6 @@
}
- $this->fsObj = new cs_fileSystem(constant('SITE_ROOT'));
parent::__construct(true);
if(defined('DEBUGPRINTOPT')) {
$this->gfObj->debugPrintOpt = constant('DEBUGPRINTOPT');
@@ -115,7 +114,7 @@
}
$this->set_version_file_location($versionFileLocation);
- $rwDir = dirname(__FILE__) .'/../rw';
+ $rwDir = dirname(__FILE__) .'/../../rw';
if(defined(__CLASS__ .'-RWDIR')) {
$rwDir = constant(__CLASS__ .'-RWDIR');
}
@@ -133,6 +132,7 @@
throw new exception(__METHOD__ .": failed to connect to database or logger error: ". $e->getMessage());
}
+ $this->fsObj = new cs_fileSystem(constant('SITE_ROOT'));
if($this->check_lockfile()) {
//there is an existing lockfile...
throw new exception(__METHOD__ .": upgrade in progress: ". $this->fsObj->read($this->lockfile));
@@ -952,20 +952,25 @@
*/
public function create_lockfile($contents) {
if(!$this->check_lockfile()) {
- if($this->fsObj->create_file($this->lockfile)) {
- if(!preg_match('/\n$/', $contents)) {
- $contents .= "\n";
+ try {
+ if($this->fsObj->create_file($this->lockfile)) {
+ if(!preg_match('/\n$/', $contents)) {
+ $contents .= "\n";
+ }
+ $writeRes = $this->fsObj->write($contents);
+ if(is_numeric($writeRes) && $writeRes > 0) {
+ $this->fsObj->closeFile();
+ }
+ else {
+ $this->error_handler(__METHOD__ .": failed to write contents (". $contents .") to lockfile");
+ }
}
- $writeRes = $this->fsObj->write($contents);
- if(is_numeric($writeRes) && $writeRes > 0) {
- $this->fsObj->closeFile();
- }
else {
- $this->error_handler(__METHOD__ .": failed to write contents (". $contents .") to lockfile");
+ $this->error_handler(__METHOD__ .": failed to create lockfile (". $this->lockfile .")");
}
}
- else {
- $this->error_handler(__METHOD__ .": failed to create lockfile (". $this->lockfile .")");
+ catch(exception $e) {
+ throw new exception(__METHOD__ .": failed to create lockfile (". $this->lockfile ." [root=". $this->fsObj->root ."] with contents (". $contents .")::: ". $e->getMessage());
}
}
else {
@@ -1081,4 +1086,4 @@
}//end upgrade{}
-?>
\ No newline at end of file
+?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-09-21 04:40:44
|
Revision: 150
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=150&view=rev
Author: crazedsanity
Date: 2009-09-21 04:40:36 +0000 (Mon, 21 Sep 2009)
Log Message:
-----------
Default db type instead of exception, dbparameters for cs-webapplibs.
/cs_phpDB.class.php:
* __construct():
-- set type as 'pgsql' if it isn't set.
-- dont' throw an exception anymore since type is always set.
/cs_webdbupgrade.class.php:
* MAIN:::
-- new (private) var $dbType=null
* __construct():
-- ARG CHANGE: ARG SHIFTED ($lockFile from #3 to #4)
-- ARG CHANGE: NEW ARG: #3 (array $dbparams=null)
-- allow an array of database parameters to be set
-- use array of paramenters vs. constants by default.
-- for constant definitions, use (modified) project name as prefix.
-- only set internal dbType if the appropriate constant is set
-- set default rwDir (don't throw an exception on missing constant)
-- user internal dbType as first argument to cs_phpDB.
/tests/testOfCSWebAppLibs.php:
* create_db():
-- use proper constants for connection parameters
* remove_tables():
-- don't force an error if dropping the tables fails.
Modified Paths:
--------------
trunk/0.3/cs_phpDB.class.php
trunk/0.3/cs_webdbupgrade.class.php
trunk/0.3/tests/testOfCSWebAppLibs.php
Modified: trunk/0.3/cs_phpDB.class.php
===================================================================
--- trunk/0.3/cs_phpDB.class.php 2009-09-10 17:39:07 UTC (rev 149)
+++ trunk/0.3/cs_phpDB.class.php 2009-09-21 04:40:36 UTC (rev 150)
@@ -33,21 +33,18 @@
//=========================================================================
public function __construct($type='pgsql') {
-
- if(strlen($type)) {
-
- require_once(dirname(__FILE__) .'/db_types/'. __CLASS__ .'__'. $type .'.class.php');
- $className = __CLASS__ .'__'. $type;
- $this->dbLayerObj = new $className;
- $this->dbType = $type;
-
- parent::__construct(true);
-
- $this->isInitialized = TRUE;
+ if(is_null($type) || !strlen($type)) {
+ $type = 'pgsql';
}
- else {
- throw new exception(__METHOD__ .": failed to give a type (". $type .")");
- }
+
+ require_once(dirname(__FILE__) .'/db_types/'. __CLASS__ .'__'. $type .'.class.php');
+ $className = __CLASS__ .'__'. $type;
+ $this->dbLayerObj = new $className;
+ $this->dbType = $type;
+
+ parent::__construct(true);
+
+ $this->isInitialized = TRUE;
}//end __construct()
//=========================================================================
Modified: trunk/0.3/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.3/cs_webdbupgrade.class.php 2009-09-10 17:39:07 UTC (rev 149)
+++ trunk/0.3/cs_webdbupgrade.class.php 2009-09-21 04:40:36 UTC (rev 150)
@@ -55,6 +55,8 @@
private $storedLogs = array();
private $debugLogs=array();
+ private $dbType=null;
+
/** List of acceptable suffixes; example "1.0.0-BETA3" -- NOTE: these MUST be in
* an order that reflects newest -> oldest; "ALPHA happens before BETA, etc. */
private $suffixList = array(
@@ -64,16 +66,19 @@
);
//=========================================================================
- public function __construct($versionFileLocation, $upgradeConfigFile, $lockFile='upgrade.lock') {
+ public function __construct($versionFileLocation, $upgradeConfigFile, array $dbParams=null, $lockFile='upgrade.lock') {
//setup configuration parameters for database connectivity.
- $dbParams = array(
- 'host' => constant(__CLASS__ .'-DB_CONNECT_HOST'),
- 'port' => constant(__CLASS__ .'-DB_CONNECT_PORT'),
- 'dbname' => constant(__CLASS__ .'-DB_CONNECT_DBNAME'),
- 'user' => constant(__CLASS__ .'-DB_CONNECT_USER'),
- 'password' => constant(__CLASS__ .'-DB_CONNECT_PASSWORD')
- );
+ if(!is_array($dbParams) || !count($dbParams)) {
+ $prefix = preg_replace('/-/', '_', $this->get_project());
+ $dbParams = array(
+ 'host' => constant($prefix .'-DB_CONNECT_HOST'),
+ 'port' => constant($prefix .'-DB_CONNECT_PORT'),
+ 'dbname' => constant($prefix .'-DB_CONNECT_DBNAME'),
+ 'user' => constant($prefix .'-DB_CONNECT_USER'),
+ 'password' => constant($prefix .'-DB_CONNECT_PASSWORD')
+ );
+ }
$this->config['DBPARAMS'] = $dbParams;
//Check for some required constants.
$requisiteConstants = array('LIBDIR');
@@ -95,8 +100,8 @@
$this->config['DB_PRIMARYKEY'] = 'version_id';
$this->sequenceName = $this->config['DB_TABLE'] .'_'. $this->config['DB_PRIMARYKEY'] .'_seq';
- if(!defined('DBTYPE')) {
- throw new exception(__METHOD__ .": required constant 'DBTYPE' not set");
+ if(defined('DBTYPE')) {
+ $this->dbType = constant('DBTYPE');
}
if(!file_exists($upgradeConfigFile) || !is_readable($upgradeConfigFile)) {
@@ -110,18 +115,17 @@
}
$this->set_version_file_location($versionFileLocation);
- if(!defined(__CLASS__ .'-RWDIR') || !is_dir(constant(__CLASS__ .'-RWDIR')) || !is_readable(constant(__CLASS__ .'-RWDIR')) || !is_writable(constant(__CLASS__ .'-RWDIR'))) {
- throw new exception(__METHOD__ .": missing RWDIR (". constant(__CLASS__ .'-RWDIR') .") or isn't readable/writable");
+ $rwDir = dirname(__FILE__) .'/../rw';
+ if(defined(__CLASS__ .'-RWDIR')) {
+ $rwDir = constant(__CLASS__ .'-RWDIR');
}
- else {
- $this->config['RWDIR'] = constant(__CLASS__ .'-RWDIR');
- }
+ $this->config['RWDIR'] = $rwDir;
if(is_null($lockFile) || !strlen($lockFile)) {
$lockFile = 'upgrade.lock';
}
$this->lockfile = $this->config['RWDIR'] .'/'. $lockFile;
- $this->db = new cs_phpDB(constant('DBTYPE'));
+ $this->db = new cs_phpDB($this->dbType);
try {
$this->db->connect($this->config['DBPARAMS']);
}
@@ -137,7 +141,7 @@
$this->check_internal_upgrades();
try {
- $loggerDb = new cs_phpDB(constant('DBTYPE'));
+ $loggerDb = new cs_phpDB($this->dbType);
$loggerDb->connect($this->config['DBPARAMS'], true);
$this->logsObj = new cs_webdblogger($loggerDb, "Upgrade ". $this->projectName, false);
}
Modified: trunk/0.3/tests/testOfCSWebAppLibs.php
===================================================================
--- trunk/0.3/tests/testOfCSWebAppLibs.php 2009-09-10 17:39:07 UTC (rev 149)
+++ trunk/0.3/tests/testOfCSWebAppLibs.php 2009-09-21 04:40:36 UTC (rev 150)
@@ -26,11 +26,11 @@
//--------------------------------------------------------------------------
private function create_dbconn() {
$dbParams = array(
- 'host' => constant('DB_PG_HOST'),
- 'dbname' => constant('DB_PG_DBNAME'),
- 'user' => constant('DB_PG_DBUSER'),
- 'password' => constant('DB_PG_DBPASS'),
- 'port' => constant('DB_PG_PORT')
+ 'host' => constant('cs_webapplibs-DB_CONNECT_HOST'),
+ 'dbname' => constant('cs_webapplibs-DB_CONNECT_DBNAME'),
+ 'user' => constant('cs_webapplibs-DB_CONNECT_USER'),
+ 'password' => constant('cs_webapplibs-DB_CONNECT_PASSWORD'),
+ 'port' => constant('cs_webapplibs-DB_CONNECT_PORT')
);
$db = new cs_phpDB(constant('DBTYPE'));
$db->connect($dbParams);
@@ -55,7 +55,7 @@
}
catch(exception $e) {
//force an error.
- $this->assertTrue(false, "Error while dropping (". $name .")::: ". $e->getMessage());
+ //$this->assertTrue(false, "Error while dropping (". $name .")::: ". $e->getMessage());
}
}
}//end remove_tables()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-09-10 17:39:14
|
Revision: 149
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=149&view=rev
Author: crazedsanity
Date: 2009-09-10 17:39:07 +0000 (Thu, 10 Sep 2009)
Log Message:
-----------
If cs_authToken doesn't get a database object, throw an exception about it.
Modified Paths:
--------------
trunk/0.3/cs_authToken.class.php
Modified: trunk/0.3/cs_authToken.class.php
===================================================================
--- trunk/0.3/cs_authToken.class.php 2009-09-09 15:30:37 UTC (rev 148)
+++ trunk/0.3/cs_authToken.class.php 2009-09-10 17:39:07 UTC (rev 149)
@@ -32,16 +32,21 @@
*/
public function __construct(cs_phpDB $db) {
- if($db->is_connected()) {
- $this->db = $db;
+ if(is_object($db)) {
+ if($db->is_connected()) {
+ $this->db = $db;
+ }
+ else {
+ throw new exception(__METHOD__ .": database object not connected");
+ }
+ parent::__construct(true);
+
+ $upg = new cs_webdbupgrade(dirname(__FILE__) .'/VERSION', dirname(__FILE__) .'/upgrades/upgrade.xml');
+ $upg->check_versions(true);
}
else {
- throw new exception(__METHOD__ .": database object not connected");
+ throw new exception(__METHOD__ .": invalid database object (". $db .")");
}
- parent::__construct(true);
-
- $upg = new cs_webdbupgrade(dirname(__FILE__) .'/VERSION', dirname(__FILE__) .'/upgrades/upgrade.xml');
- $upg->check_versions(true);
}//end __construct()
//=========================================================================
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cra...@us...> - 2009-09-09 15:30:46
|
Revision: 148
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=148&view=rev
Author: crazedsanity
Date: 2009-09-09 15:30:37 +0000 (Wed, 09 Sep 2009)
Log Message:
-----------
Default to the first section found for cs_siteConfig{}'s main section.
/cs_siteConfig.class.php:
* __construct():
-- ARG CHANGE: DEFAULT VALUE MODIFIED: #2 ($section=null FROM
$section='MAIN').
-- if the section isn't passed, assume the first tag found under the
root element contains the main configuration.
Modified Paths:
--------------
trunk/0.3/cs_siteConfig.class.php
Modified: trunk/0.3/cs_siteConfig.class.php
===================================================================
--- trunk/0.3/cs_siteConfig.class.php 2009-09-08 14:24:15 UTC (rev 147)
+++ trunk/0.3/cs_siteConfig.class.php 2009-09-09 15:30:37 UTC (rev 148)
@@ -73,7 +73,7 @@
* @return NULL (PASS) object successfully created
* @return exception (FAIL) failed to create object (see exception message)
*/
- public function __construct($configFileLocation, $section='MAIN', $setVarPrefix=null) {
+ public function __construct($configFileLocation, $section=null, $setVarPrefix=null) {
$section = strtoupper($section);
$this->setVarPrefix=$setVarPrefix;
@@ -101,6 +101,13 @@
throw new exception(__METHOD__ .": invalid configuration file (". $configFileLocation .")");
}
+ if(is_null($section) || !strlen($section)) {
+ $myData = $this->xmlReader->get_path($this->xmlReader->get_root_element());
+ unset($myData['type'], $myData['attributes']);
+ $myData = array_keys($myData);
+ $section = $myData[0];
+ }
+
if(strlen($section)) {
try {
$this->parse_config();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|