Page MenuHomeDevCentral

D3797.id9837.diff
No OneTemporary

D3797.id9837.diff

diff --git a/workspaces/src/Engines/Framework/Context.php b/workspaces/src/Engines/Framework/Context.php
--- a/workspaces/src/Engines/Framework/Context.php
+++ b/workspaces/src/Engines/Framework/Context.php
@@ -20,7 +20,7 @@
use Keruald\Database\DatabaseEngine;
use Smarty\Smarty;
use User;
-use WorkSpace;
+use Waystone\Workspaces\Engines\Workspaces\WorkSpace;
/**
* Context class
diff --git a/workspaces/src/includes/workspaces/Workspace.php b/workspaces/src/Engines/Workspaces/Workspace.php
rename from workspaces/src/includes/workspaces/Workspace.php
rename to workspaces/src/Engines/Workspaces/Workspace.php
--- a/workspaces/src/includes/workspaces/Workspace.php
+++ b/workspaces/src/Engines/Workspaces/Workspace.php
@@ -15,9 +15,14 @@
* @filesource
*/
+namespace Waystone\Workspaces\Engines\Workspaces;
+
use Waystone\Workspaces\Engines\Errors\ErrorHandling;
use Waystone\Workspaces\Engines\Framework\Context;
+use Cache;
+use User;
+
/**
* Workspace class
*
@@ -41,7 +46,7 @@
*
* @param int $id the primary key
*/
- function __construct ($id = NULL) {
+ function __construct ($id = null) {
if ($id) {
$this->id = $id;
$this->load_from_database();
@@ -52,10 +57,18 @@
* Loads the object Workspace (ie fill the properties) from the $_POST array
*/
function load_from_form () {
- if (array_key_exists('code', $_POST)) $this->code = $_POST['code'];
- if (array_key_exists('name', $_POST)) $this->name = $_POST['name'];
- if (array_key_exists('created', $_POST)) $this->created = $_POST['created'];
- if (array_key_exists('description', $_POST)) $this->description = $_POST['description'];
+ if (array_key_exists('code', $_POST)) {
+ $this->code = $_POST['code'];
+ }
+ if (array_key_exists('name', $_POST)) {
+ $this->name = $_POST['name'];
+ }
+ if (array_key_exists('created', $_POST)) {
+ $this->created = $_POST['created'];
+ }
+ if (array_key_exists('description', $_POST)) {
+ $this->description = $_POST['description'];
+ }
}
/**
@@ -73,19 +86,25 @@
* Loads the specified workspace from code
*
* @param string $code The workspace code
+ *
* @return Workspace The specified workspace instance
*/
public static function fromCode ($code) {
global $db;
$code = $db->escape($code);
- $sql = "SELECT * FROM " . TABLE_WORKSPACES . " WHERE workspace_code = '" . $code . "'";
- if (!$result = $db->query($sql)) ErrorHandling::messageAndDie(SQL_ERROR, "Unable to query workspaces", '', __LINE__, __FILE__, $sql);
+ $sql = "SELECT * FROM " . TABLE_WORKSPACES . " WHERE workspace_code = '"
+ . $code . "'";
+ if (!$result = $db->query($sql)) {
+ ErrorHandling::messageAndDie(SQL_ERROR,
+ "Unable to query workspaces", '', __LINE__, __FILE__, $sql);
+ }
if (!$row = $db->fetchRow($result)) {
throw new Exception("Workspace unknown: " . $code);
}
$workspace = new Workspace();
$workspace->load_from_row($row);
+
return $workspace;
}
@@ -95,13 +114,19 @@
function load_from_database () {
global $db;
$id = $db->escape($this->id);
- $sql = "SELECT * FROM " . TABLE_WORKSPACES . " WHERE workspace_id = '" . $id . "'";
- if (!$result = $db->query($sql)) ErrorHandling::messageAndDie(SQL_ERROR, "Unable to query workspaces", '', __LINE__, __FILE__, $sql);
+ $sql = "SELECT * FROM " . TABLE_WORKSPACES . " WHERE workspace_id = '"
+ . $id . "'";
+ if (!$result = $db->query($sql)) {
+ ErrorHandling::messageAndDie(SQL_ERROR,
+ "Unable to query workspaces", '', __LINE__, __FILE__, $sql);
+ }
if (!$row = $db->fetchRow($result)) {
$this->lastError = "Workspace unknown: " . $this->id;
+
return false;
}
$this->load_from_row($row);
+
return true;
}
@@ -118,9 +143,11 @@
$description = $db->escape($this->description);
//Updates or inserts
- $sql = "REPLACE INTO " . TABLE_WORKSPACES . " (`workspace_id`, `workspace_code`, `workspace_name`, `workspace_created`, `workspace_description`) VALUES ('$id', '$code', '$name', '$created', '$description')";
+ $sql = "REPLACE INTO " . TABLE_WORKSPACES
+ . " (`workspace_id`, `workspace_code`, `workspace_name`, `workspace_created`, `workspace_description`) VALUES ('$id', '$code', '$name', '$created', '$description')";
if (!$db->query($sql)) {
- ErrorHandling::messageAndDie(SQL_ERROR, "Unable to save", '', __LINE__, __FILE__, $sql);
+ ErrorHandling::messageAndDie(SQL_ERROR, "Unable to save", '',
+ __LINE__, __FILE__, $sql);
}
if (!$this->id) {
@@ -132,8 +159,10 @@
/**
* Determines if the specified user has access to the current workspace
*
- * @param User the user to check
- * @return boolean true if the user has access to the current workspace ; otherwise, false.
+ * @param User $user The user to check
+ *
+ * @return boolean true if the user has access to the current workspace ;
+ * otherwise, false.
*/
public function userCanAccess (User $user) {
if ($this->id === false || $this->id === null || $this->id === '') {
@@ -144,31 +173,36 @@
return true;
}
}
+
return false;
}
/**
* Loads configuration
*
- * @param $context The site context
+ * @param Context $context The site context
*/
public function loadConfiguration (Context $context) {
global $Config;
- $file = $Config['Content']['Workspaces'] . '/' . $this->code . '/workspace.conf';
+ $file = $Config['Content']['Workspaces'] . '/' . $this->code
+ . '/workspace.conf';
if (!file_exists($file)) {
- $exceptionMessage = sprintf(Language::get('NotConfiguredWorkspace'), $file);
+ $exceptionMessage =
+ sprintf(Language::get('NotConfiguredWorkspace'), $file);
throw new Exception($exceptionMessage);
}
- $this->configuration = WorkspaceConfiguration::loadFromFile($file, $context);
+ $this->configuration =
+ WorkspaceConfiguration::loadFromFile($file, $context);
}
/**
* Gets workspaces specified user has access to.
*
* @param int $user_id The user to get his workspaces
- * @return Array A list of workspaces
+ *
+ * @return Workspace[] A list of workspaces
*/
public static function get_user_workspaces ($user_id) {
global $db;
@@ -179,7 +213,7 @@
if (!$workspaces = unserialize($cache->get("workspaces-$user_id"))) {
$clause = User::get_permissions_clause_from_user_id($user_id);
- $sql = "SELECT DISTINCT w.*
+ $sql = "SELECT DISTINCT w.*
FROM " . TABLE_PERMISSIONS . " p, " . TABLE_WORKSPACES . " w
WHERE p.target_resource_type = 'W' AND
p.target_resource_id = w.workspace_id AND
@@ -187,10 +221,11 @@
p.permission_flag > 0 AND
($clause)";
if (!$result = $db->query($sql)) {
- ErrorHandling::messageAndDie(SQL_ERROR, "Can't get user workspaces", '', __LINE__, __FILE__, $sql);
+ ErrorHandling::messageAndDie(SQL_ERROR,
+ "Can't get user workspaces", '', __LINE__, __FILE__, $sql);
}
- $workspaces = array();
+ $workspaces = [];
while ($row = $db->fetchRow($result)) {
$workspace = new Workspace();
@@ -209,17 +244,22 @@
* Determines if a string matches an existing workspace code.
*
* @param string $code The workspace code to check
- * @return boolean If the specified code matches an existing workspace, true; otherwise, false.
+ *
+ * @return boolean If the specified code matches an existing workspace,
+ * true; otherwise, false.
*/
public static function is_workspace ($code) {
global $db;
$code = $db->escape($code);
- $sql = "SELECT count(*) FROM " . TABLE_WORKSPACES . " WHERE workspace_code = '$code'";
+ $sql = "SELECT count(*) FROM " . TABLE_WORKSPACES
+ . " WHERE workspace_code = '$code'";
if (!$result = $db->query($sql)) {
- ErrorHandling::messageAndDie(SQL_ERROR, "Can't check workspace code", '', __LINE__, __FILE__, $sql);
+ ErrorHandling::messageAndDie(SQL_ERROR,
+ "Can't check workspace code", '', __LINE__, __FILE__, $sql);
}
$row = $db->fetchRow($result);
+
return ($row[0] == 1);
}
}
diff --git a/workspaces/src/includes/workspaces/WorkspaceConfiguration.php b/workspaces/src/Engines/Workspaces/WorkspaceConfiguration.php
rename from workspaces/src/includes/workspaces/WorkspaceConfiguration.php
rename to workspaces/src/Engines/Workspaces/WorkspaceConfiguration.php
--- a/workspaces/src/includes/workspaces/WorkspaceConfiguration.php
+++ b/workspaces/src/Engines/Workspaces/WorkspaceConfiguration.php
@@ -15,38 +15,50 @@
* @filesource
*/
+namespace Waystone\Workspaces\Engines\Workspaces;
+
use Waystone\Workspaces\Engines\Framework\Context;
+use ApplicationConfiguration;
+use ObjectDeserializableWithContext;
+
/**
- * Workspace configuration class
- *
- * This class maps the workspaces table.
- */
+ * Workspace configuration class
+ *
+ * This class maps the workspaces table.
+ */
class WorkspaceConfiguration implements ObjectDeserializableWithContext {
+
/**
- * @var Array applications (each element is an instance of ApplicationConfiguration)
+ * @var array applications (each element is an instance of
+ * ApplicationConfiguration)
*/
public $applications = [];
/**
- * @var Array authentication methods for this workspace (each element is an instance of AuthenticationMethod)
+ * @var array authentication methods for this workspace (each element is an
+ * instance of AuthenticationMethod)
*/
public $authenticationMethods = [];
/**
- * @var Array disclaimers (each element a string)
+ * @var array disclaimers (each element a string)
*/
public $disclaimers = [];
/**
- * @var Array collections (each key a string to the collection name, each value a string to the collection document type)
+ * @var array collections (each key a string to the collection name, each
+ * value a string to the collection document type)
*/
public $collections = [];
/**
- * Determines if internal Obsidian Workspaces authentication can be used to login on this workspace URL
+ * Determines if internal Obsidian Workspaces authentication can be used to
+ * login on this workspace URL
*
- * @return boolean True if a user not logged in Obsidian Workspaces going to a workspace URL should be offered to login through Obsidian ; otherwise, false.
+ * @return boolean True if a user not logged in Obsidian Workspaces going
+ * to a workspace URL should be offered to login through
+ * Obsidian ; otherwise, false.
*/
public $allowInternalAuthentication = true;
@@ -68,22 +80,29 @@
foreach ($this->applications as $application) {
$controllers[$application->bind] = $application;
}
+
return $controllers;
}
/**
* Determines if the URL fragment matches a controller bound to it.
*
- * @param ApplicationConfiguration $applicationConfiguration The application configuration
- * @return boolean true if the URL fragment matches an application controller's bind
+ * @param ApplicationConfiguration $applicationConfiguration The
+ * application
+ * configuration
+ *
+ * @return boolean true if the URL fragment matches an application
+ * controller's bind
*/
public function hasControllerBind ($url, &$applicationConfiguration) {
foreach ($this->applications as $application) {
if ($application->bind == $url) {
$applicationConfiguration = $application;
+
return true;
}
}
+
return false;
}
@@ -91,7 +110,8 @@
* Loads a WorkspaceConfiguration instance from an object
*
* @param object $data The object to deserialize
- * @param Context The site context
+ * @param Context $context The site context
+ *
* @return WorkspaceConfiguration The deserialized instance
*/
public static function loadFromObject ($data, $context) {
@@ -106,14 +126,16 @@
$controllerClass = $applicationData->name;
if (!class_exists($controllerClass)) {
- trigger_error("Application controller doesn't exist: $controllerClass. If you've just added application code, update includes/autoload.php file to register your new classes.", E_USER_WARNING);
+ trigger_error("Application controller doesn't exist: $controllerClass. If you've just added application code, update includes/autoload.php file to register your new classes.",
+ E_USER_WARNING);
continue;
}
$configurationClass = $controllerClass . 'Configuration';
if (!class_exists($configurationClass)) {
$configurationClass = "ApplicationConfiguration";
}
- $instance->applications[] = $configurationClass::loadFromObject($applicationData);
+ $instance->applications[] =
+ $configurationClass::loadFromObject($applicationData);
}
}
@@ -152,8 +174,11 @@
throw new Exception("A collection has been declared without name in the workspace configuration.");
}
$name = $collection->name;
- if (!property_exists($collection, 'global') || !$collection->global) {
- $name = WorkspaceConfiguration::getCollectionNameWithPrefix($context->workspace, $name);
+ if (!property_exists($collection, 'global')
+ || !$collection->global) {
+ $name =
+ WorkspaceConfiguration::getCollectionNameWithPrefix($context->workspace,
+ $name);
}
if (property_exists($collection, 'documentType')) {
$type = $collection->documentType;
@@ -183,11 +208,15 @@
/**
* Gets the full name of a collection, with the workspace prefix
*
- * @param $workspace The current workspace
- * @param $workspace The collection name
+ * @param Workspace $workspace The current workspace
+ * @param string $name The collection name
+ *
* @return string The full name of the collection
*/
- public static function getCollectionNameWithPrefix (Workspace $workspace, $name) {
+ public static function getCollectionNameWithPrefix (
+ Workspace $workspace,
+ string $name
+ ) {
return $workspace->code . '-' . $name;
}
@@ -197,8 +226,10 @@
public static function loadFromFile ($file, $context) {
$object = json_decode(file_get_contents($file));
if ($object === null) {
- throw new Exception("Can't parse configuration file: " . json_last_error_msg());
+ throw new Exception("Can't parse configuration file: "
+ . json_last_error_msg());
}
+
return self::loadFromObject($object, $context);
}
}
diff --git a/workspaces/src/includes/GlobalFunctions.php b/workspaces/src/includes/GlobalFunctions.php
--- a/workspaces/src/includes/GlobalFunctions.php
+++ b/workspaces/src/includes/GlobalFunctions.php
@@ -1,5 +1,7 @@
<?php
+use Waystone\Workspaces\Engines\Workspaces\Workspace;
+
////////////////////////////////////////////////////////////////////////////////
/// ///
/// Information helper functions ///
diff --git a/workspaces/src/includes/apps/Application.php b/workspaces/src/includes/apps/Application.php
--- a/workspaces/src/includes/apps/Application.php
+++ b/workspaces/src/includes/apps/Application.php
@@ -16,6 +16,7 @@
*/
use Waystone\Workspaces\Engines\Controller\Controller;
+use Waystone\Workspaces\Engines\Workspaces\WorkspaceConfiguration;
/**
* Application class
diff --git a/workspaces/src/includes/apps/ApplicationConfiguration.php b/workspaces/src/includes/apps/ApplicationConfiguration.php
--- a/workspaces/src/includes/apps/ApplicationConfiguration.php
+++ b/workspaces/src/includes/apps/ApplicationConfiguration.php
@@ -15,6 +15,8 @@
* @filesource
*/
+use Waystone\Workspaces\Engines\Workspaces\WorkspaceConfiguration;
+
/**
* Application configuration class
*
diff --git a/workspaces/src/includes/objects/user.php b/workspaces/src/includes/objects/user.php
--- a/workspaces/src/includes/objects/user.php
+++ b/workspaces/src/includes/objects/user.php
@@ -17,6 +17,7 @@
*/
use Waystone\Workspaces\Engines\Errors\ErrorHandling;
+use Waystone\Workspaces\Engines\Workspaces\Workspace;
/**
* User class
diff --git a/workspaces/src/index.php b/workspaces/src/index.php
--- a/workspaces/src/index.php
+++ b/workspaces/src/index.php
@@ -19,6 +19,7 @@
use Waystone\Workspaces\Engines\Errors\ErrorHandling;
use Waystone\Workspaces\Engines\Framework\Application;
+use Waystone\Workspaces\Engines\Workspaces\Workspace;
////////////////////////////////////////////////////////////////////////////////
///

File Metadata

Mime Type
text/plain
Expires
Fri, Oct 24, 04:44 (20 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3099660
Default Alt Text
D3797.id9837.diff (17 KB)

Event Timeline