From b528536b7ec821d057bf45208da0801c1e2cb280 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sat, 5 Oct 2013 20:03:12 +0200 Subject: [PATCH] UUID support --- public_html/classes/node.php | 8 +- public_html/classes/property.php | 10 +-- public_html/classes/relationship.php | 10 +-- public_html/includes/base.php | 7 ++ public_html/includes/uuid.php | 111 +++++++++++++++++++++++++++ public_html/modules/nodes/create.php | 40 ++++++++-- public_html/rewrite.php | 3 +- 7 files changed, 167 insertions(+), 22 deletions(-) create mode 100644 public_html/includes/uuid.php diff --git a/public_html/classes/node.php b/public_html/classes/node.php index 54856dc..db75b45 100644 --- a/public_html/classes/node.php +++ b/public_html/classes/node.php @@ -22,12 +22,12 @@ class Node extends CPHPDatabaseRecordClass public $prototype = array( 'string' => array( "Name" => "Name", - "Notes" => "Notes" - ), - 'numeric' => array( + "Notes" => "Notes", "TypeId" => "TypeId", "ParentRevisionId" => "ParentRevisionId", - "FirstRevisionId" => "FirstRevisionId", + "FirstRevisionId" => "FirstRevisionId" + ), + 'numeric' => array( "UserId" => "UserId" ), 'timestamp' => array( diff --git a/public_html/classes/property.php b/public_html/classes/property.php index 426022d..1e9134d 100644 --- a/public_html/classes/property.php +++ b/public_html/classes/property.php @@ -23,15 +23,15 @@ class Property extends CPHPDatabaseRecordClass 'string' => array( "Name" => "Name", "Value" => "Value", - "Source" => "Source" - ), - 'numeric' => array( + "Source" => "Source", "TypeId" => "TypeId", "ParentRevisionId" => "ParentRevisionId", "FirstRevisionId" => "FirstRevisionId", - "UserId" => "UserId", "NodeId" => "NodeId", - "RelationshipId" => "RelationshipId", + "RelationshipId" => "RelationshipId" + ), + 'numeric' => array( + "UserId" => "UserId", "Reliability" => "Reliability" ), 'timestamp' => array( diff --git a/public_html/classes/relationship.php b/public_html/classes/relationship.php index e8aab51..515bf55 100644 --- a/public_html/classes/relationship.php +++ b/public_html/classes/relationship.php @@ -23,15 +23,15 @@ class Relationship extends CPHPDatabaseRecordClass 'string' => array( "Name" => "Name", "Source" => "Source", - "Notes" => "Notes" - ), - 'numeric' => array( + "Notes" => "Notes", "TypeId" => "TypeId", "ParentRevisionId" => "ParentRevisionId", "FirstRevisionId" => "FirstRevisionId", - "UserId" => "UserId", "FromNodeId" => "FromNodeId", - "ToNodeId" => "ToNodeId", + "ToNodeId" => "ToNodeId" + ), + 'numeric' => array( + "UserId" => "UserId", "Reliability" => "Reliability" ), 'timestamp' => array( diff --git a/public_html/includes/base.php b/public_html/includes/base.php index a9c4cf8..35a8f31 100644 --- a/public_html/includes/base.php +++ b/public_html/includes/base.php @@ -16,3 +16,10 @@ if(!isset($_APP)) { die("Unauthorized."); } $_CPHP = true; $_CPHP_CONFIG = "../config.json"; require("cphp/base.php"); + +require("uuid.php"); + +function generate_uuid() +{ + return UUID::v4(); +} diff --git a/public_html/includes/uuid.php b/public_html/includes/uuid.php new file mode 100644 index 0000000..a24527e --- /dev/null +++ b/public_html/includes/uuid.php @@ -0,0 +1,111 @@ +uMethod == "post") if(empty($sErrors)) { + $uNodeId = generate_uuid(); + $sNode = new Node(); + $sNode->uId = $uNodeId; $sNode->uName = $_POST['name']; $sNode->uNotes = $_POST['notes']; - $sNode->uTypeId = 0; - $sNode->uParentRevisionId = 0; - $sNode->uFirstRevisionId = 0; + $sNode->uTypeId = ""; + $sNode->uParentRevisionId = ""; + $sNode->uFirstRevisionId = $uNodeId; $sNode->uUserId = 0; $sNode->uCreationDate = time(); $sNode->uLatestRevision = true; $sNode->InsertIntoDatabase(); - /* Update the entry to refer to itself as the first revision */ - $sNode->uFirstRevisionId = $sNode->sId; - $sNode->InsertIntoDatabase(); + /* Insert properties, if any */ + foreach(array_combine($_POST['property_name'], $_POST['property_value']) as $property_name => $property_value) + { + if(!empty($property_name)) + { + $uPropertyId = generate_uuid(); + + $sProperty = new Property(); + + $sProperty->uId = $uPropertyId; + $sProperty->uName = $property_name; + $sProperty->uValue = $property_value; + $sProperty->uSource = ""; + + $sProperty->uTypeId = ""; + $sProperty->uParentRevisionId = ""; + $sProperty->uFirstRevisionId = $uPropertyId; + $sProperty->uNodeId = $uNodeId; + $sProperty->uRelationshipId = ""; + $sProperty->uReliability = 1; /* Normal */ + $sProperty->uCreationDate = time(); + $sProperty->uLatestRevision = true; + + $sProperty->InsertIntoDatabase(); + } + } $sData = array( "result" => "success", "message" => "Node '" . htmlspecialchars($_POST['name']) . "' created.", - "node_id" => $sNode->sId + "node_id" => $uNodeId ); } else diff --git a/public_html/rewrite.php b/public_html/rewrite.php index f668c87..365c1f1 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -42,7 +42,8 @@ if(!empty($router->uVariables['json'])) { echo(json_encode($sData)); } - +/* $sNode = new Node(1); $sNode->uName = random_string(15); $sNode->InsertIntoDatabase(); +*/