diff --git a/CHANGELOG.md b/CHANGELOG.md
old mode 100755
new mode 100644
diff --git a/application/cache/index.html b/application/cache/index.html
old mode 100755
new mode 100644
diff --git a/application/config/autoload.php b/application/config/autoload.php
old mode 100755
new mode 100644
diff --git a/application/config/config.php b/application/config/config.php
old mode 100755
new mode 100644
diff --git a/application/config/constants.php b/application/config/constants.php
old mode 100755
new mode 100644
diff --git a/application/config/database.php b/application/config/database.php
old mode 100755
new mode 100644
diff --git a/application/config/doctypes.php b/application/config/doctypes.php
old mode 100755
new mode 100644
diff --git a/application/config/extensions/.placeholder b/application/config/extensions/.placeholder
new file mode 100644
index 000000000..8d1c8b69c
--- /dev/null
+++ b/application/config/extensions/.placeholder
@@ -0,0 +1 @@
+
diff --git a/application/config/fhcomplete.php b/application/config/fhcomplete.php
old mode 100755
new mode 100644
index 3c540ea65..b1fd96f0f
--- a/application/config/fhcomplete.php
+++ b/application/config/fhcomplete.php
@@ -208,6 +208,7 @@ $config['fhc_acl'] = array
'system.tbl_webservicerecht' => 'basis/webservicerecht',
'system.tbl_webservicetyp' => 'basis/webservicetyp',
'system.tbl_udf' => 'system/udf',
+ 'system.tbl_extensions' => 'system/extensions',
'testtool.tbl_ablauf' => 'basis/ablauf',
'testtool.tbl_antwort' => 'basis/antwort',
'testtool.tbl_frage' => 'basis/frage',
diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php
old mode 100755
new mode 100644
diff --git a/application/config/hooks.php b/application/config/hooks.php
old mode 100755
new mode 100644
diff --git a/application/config/index.html b/application/config/index.html
old mode 100755
new mode 100644
diff --git a/application/config/mail.php b/application/config/mail.php
old mode 100755
new mode 100644
diff --git a/application/config/memcached.php b/application/config/memcached.php
old mode 100755
new mode 100644
diff --git a/application/config/migration.php b/application/config/migration.php
old mode 100755
new mode 100644
diff --git a/application/config/mimes.php b/application/config/mimes.php
old mode 100755
new mode 100644
diff --git a/application/config/profiler.php b/application/config/profiler.php
old mode 100755
new mode 100644
diff --git a/application/config/roles.php b/application/config/roles.php
old mode 100755
new mode 100644
diff --git a/application/config/routes.php b/application/config/routes.php
old mode 100755
new mode 100644
diff --git a/application/config/smileys.php b/application/config/smileys.php
old mode 100755
new mode 100644
diff --git a/application/config/user_agents.php b/application/config/user_agents.php
old mode 100755
new mode 100644
diff --git a/application/controllers/Redirect.php b/application/controllers/Redirect.php
index 99d459771..ffe135003 100644
--- a/application/controllers/Redirect.php
+++ b/application/controllers/Redirect.php
@@ -31,9 +31,6 @@ class Redirect extends FHC_Controller
// Loads model MessageTokenModel
$this->load->model('system/MessageToken_model', 'MessageTokenModel');
-
- // Loads library OrganisationseinheitLib
- $this->load->library('OrganisationseinheitLib');
}
/**
@@ -55,10 +52,23 @@ class Redirect extends FHC_Controller
if ($oe_kurzbz != null && $oe_kurzbz != '')
{
- $rootOE = $this->organisationseinheitlib->getRoot($oe_kurzbz);
- if ($rootOE->error)
+ $organisationRoot = null;
+ $getOERoot = $this->MessageTokenModel->getOERoot($oe_kurzbz);
+ if ($getOERoot) // If no errors occurred
{
- show_error($rootOE->retval);
+ // If data are present
+ if (is_array($getOERoot->result()) && count($getOERoot->result()) > 0)
+ {
+ $organisationseinheit = $getOERoot->result()[0];
+ if ($organisationseinheit->oe_kurzbz == null)
+ {
+ show_error('No organisation unit present in the message');
+ }
+ else
+ {
+ $organisationRoot = $organisationseinheit->oe_kurzbz;
+ }
+ }
}
$addonAufnahmeUrls = $this->config->item('addons_aufnahme_url');
@@ -66,10 +76,10 @@ class Redirect extends FHC_Controller
if (isset($token)
&& hasData($msg)
&& is_array($addonAufnahmeUrls)
- && hasData($rootOE)
- && isset($addonAufnahmeUrls[$rootOE->retval[0]->oe_kurzbz]))
+ && $organisationRoot != null
+ && isset($addonAufnahmeUrls[$organisationRoot]))
{
- redirect($addonAufnahmeUrls[$rootOE->retval[0]->oe_kurzbz] . '?token=' . $token);
+ redirect($addonAufnahmeUrls[$organisationRoot] . '?token=' . $token);
}
}
}
diff --git a/application/controllers/ViewMessage.php b/application/controllers/ViewMessage.php
old mode 100755
new mode 100644
diff --git a/application/controllers/Vilesci.php b/application/controllers/Vilesci.php
old mode 100755
new mode 100644
diff --git a/application/controllers/extensions/.placeholder b/application/controllers/extensions/.placeholder
new file mode 100644
index 000000000..8d1c8b69c
--- /dev/null
+++ b/application/controllers/extensions/.placeholder
@@ -0,0 +1 @@
+
diff --git a/application/controllers/index.html b/application/controllers/index.html
old mode 100755
new mode 100644
diff --git a/application/controllers/system/Login.php b/application/controllers/system/Login.php
old mode 100755
new mode 100644
diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php
old mode 100755
new mode 100644
diff --git a/application/controllers/system/Vorlage.php b/application/controllers/system/Vorlage.php
old mode 100755
new mode 100644
diff --git a/application/controllers/system/extensions/Manager.php b/application/controllers/system/extensions/Manager.php
new file mode 100644
index 000000000..db56b0d8b
--- /dev/null
+++ b/application/controllers/system/extensions/Manager.php
@@ -0,0 +1,83 @@
+load->helper(array('form', 'url'));
+
+ // Loads the extensions library
+ $this->load->library('ExtensionsLib');
+ }
+
+ /**
+ *
+ */
+ public function index()
+ {
+ $viewData = array(
+ 'extensions' => $this->extensionslib->getInstalledExtensions()
+ );
+
+ $this->load->view('system/extensions/manager.php', $viewData);
+ }
+
+ /**
+ *
+ */
+ public function toggleExtension()
+ {
+ $toggleExtension = false;
+
+ $extension_id = $this->input->post('extension_id');
+ $enabled = $this->input->post('enabled');
+
+ if ($enabled === 'true')
+ {
+ $toggleExtension = $this->extensionslib->enableExtension($extension_id);
+ }
+ else
+ {
+ $toggleExtension = $this->extensionslib->disableExtension($extension_id);
+ }
+
+ $this->output
+ ->set_content_type('application/json')
+ ->set_output(json_encode($toggleExtension));
+ }
+
+ /**
+ *
+ */
+ public function delExtension()
+ {
+ $delExtension = false;
+
+ $extension_id = $this->input->post('extension_id');
+
+ $delExtension = $this->extensionslib->delExtension($extension_id);
+
+ $this->output
+ ->set_content_type('application/json')
+ ->set_output(json_encode($delExtension));
+ }
+
+ /**
+ *
+ */
+ public function uploadExtension()
+ {
+ $this->extensionslib->installExtension();
+ }
+}
diff --git a/application/core/index.html b/application/core/index.html
old mode 100755
new mode 100644
diff --git a/application/helpers/extensions/.placeholder b/application/helpers/extensions/.placeholder
new file mode 100644
index 000000000..8d1c8b69c
--- /dev/null
+++ b/application/helpers/extensions/.placeholder
@@ -0,0 +1 @@
+
diff --git a/application/helpers/index.html b/application/helpers/index.html
old mode 100755
new mode 100644
diff --git a/application/hooks/extensions/.placeholder b/application/hooks/extensions/.placeholder
new file mode 100644
index 000000000..8d1c8b69c
--- /dev/null
+++ b/application/hooks/extensions/.placeholder
@@ -0,0 +1 @@
+
diff --git a/application/hooks/index.html b/application/hooks/index.html
old mode 100755
new mode 100644
diff --git a/application/index.html b/application/index.html
old mode 100755
new mode 100644
diff --git a/application/language/de-AT/index.html b/application/language/de-AT/index.html
old mode 100755
new mode 100644
diff --git a/application/language/index.html b/application/language/index.html
old mode 100755
new mode 100644
diff --git a/application/language/system/index.html b/application/language/system/index.html
old mode 100755
new mode 100644
diff --git a/application/libraries/EPrintfLib.php b/application/libraries/EPrintfLib.php
new file mode 100644
index 000000000..dbef1348c
--- /dev/null
+++ b/application/libraries/EPrintfLib.php
@@ -0,0 +1,138 @@
+ "red", 33 => "orange");
+ // Used to set if the migration process is called via command line or via browser
+ private $cli;
+
+ /**
+ * Object initialization
+ */
+ public function __construct()
+ {
+ // Get code igniter instance
+ $this->ci =& get_instance();
+
+ $this->setCli();
+ }
+
+ // -------------------------------------------------------------------------------------------------
+ // Public methods
+
+ /**
+ * Prints a formatted message
+ */
+ public function printMessage($message)
+ {
+ $this->_print(EPrintfLib::MSG_PREFIX, $message);
+ }
+
+ /**
+ * Prints a formatted info
+ */
+ public function printInfo($info)
+ {
+ $this->_print(EPrintfLib::INFO_PREFIX, $info, EPrintfLib::INFO_COLOR);
+ }
+
+ /**
+ * Prints a formatted error
+ */
+ public function printError($error)
+ {
+ $this->_print(EPrintfLib::ERROR_PREFIX, $error, EPrintfLib::ERROR_COLOR);
+ }
+
+ /**
+ * Print only the end of line
+ */
+ public function printEOL()
+ {
+ echo $this->getEOL();
+ }
+
+ // -------------------------------------------------------------------------------------------------
+ // Private methods
+
+ /**
+ * Set property cli to false if the migration process is called via command line
+ * otherwise to false if it's called via browser
+ */
+ private function setCli()
+ {
+ if ($this->ci->input->is_cli_request())
+ {
+ $this->cli = true;
+ }
+ else
+ {
+ $this->cli = false;
+ }
+ }
+
+ /**
+ * Returns the character of end of line
+ * PHP_EOL platform dependent if cli is true
+ * Tag
if cli is false
+ */
+ private function getEOL()
+ {
+ if ($this->cli === true)
+ {
+ return PHP_EOL;
+ }
+ else
+ {
+ return "
";
+ }
+ }
+
+ /**
+ * Returns the string needed to color the output
+ */
+ private function getColored($color)
+ {
+ $colored = "%s";
+
+ if (!is_null($color))
+ {
+ if ($this->cli === true)
+ {
+ $colored = "\033[".$color."m%s\033[37m";
+ }
+ else
+ {
+ $colored = "HTML_COLORS[$color]."\">%s";
+ }
+ }
+
+ return $colored;
+ }
+
+ /**
+ * Print a message, even colored if specified
+ */
+ private function _print($prefix, $text, $color = null)
+ {
+ printf($this->getColored($color), sprintf("%s %s".$this->getEOL(), $prefix, $text));
+ }
+}
diff --git a/application/libraries/ExtensionsLib.php b/application/libraries/ExtensionsLib.php
new file mode 100644
index 000000000..4fa0778e9
--- /dev/null
+++ b/application/libraries/ExtensionsLib.php
@@ -0,0 +1,884 @@
+ci =& get_instance();
+
+ // Loads message configurationx
+ $this->ci->config->load('message');
+
+ // Loads EPrintfLib
+ $this->ci->load->library('EPrintfLib');
+
+ // Loading models
+ $this->ci->load->model('system/Extensions_model', 'ExtensionsModel');
+
+ // Set default values fot class properties
+ $this->_errorOccurred = false;
+ $this->_currentInstalledExtensionVersion = 0;
+ }
+
+ // -------------------------------------------------------------------------------------------------
+ // Public methods
+
+ /**
+ * Main method to install an extension
+ */
+ public function installExtension()
+ {
+ $extensionDB = null; // contains data from DB about an extension
+ $extensionJson = null; // contains the extension.json data
+
+ $this->_printInfo('WARNING!!! Please do not change page or stop this procedure before it is finished');
+
+ $this->_loadUploadLibrary(); // loads CI upload library
+
+ $uploadData = $this->_uploadExtension(); // perform the upload of the file and returns info about it
+
+ if ($uploadData != null) // if no error occurred
+ {
+ $this->_extractExtension($uploadData->fullPath); // extract the archive of the uploaded extension
+
+ if (!$this->_errorOccurred) // if no error occurred
+ {
+ // Retives data about any previous installation of this extension
+ $extensionDB = $this->_loadPreviousInstallation($uploadData->extensionName);
+ }
+
+ if (!$this->_errorOccurred) // if no error occurred
+ {
+ // Checks the structure of the uploaded extension
+ $this->_chkFSStructure($uploadData->extensionName);
+ }
+
+ if (!$this->_errorOccurred) // if no error occurred
+ {
+ // Checks file extension.json and returns its content
+ $extensionJson = $this->_chkExtensionJson($uploadData->extensionName, $extensionDB);
+ }
+
+ if ($extensionJson != null) // if no error occurred
+ {
+ $this->_printStart('Proceding with the installation of the extension: '.$extensionJson->name);
+ $this->_printEnd();
+
+ $this->_cleanPreviousInstallation($extensionJson); // cleans any previous installation
+
+ $this->_installExtension($extensionJson); // records extension data in DB
+
+ if (!$this->_errorOccurred) // if no error occurred
+ {
+ // Loads and executes neede SQL scripts
+ $this->_loadSQLs(
+ ExtensionsLib::UPLOAD_PATH.$extensionJson->name.'/'.ExtensionsLib::SQL_DIRECTORY,
+ $extensionJson
+ );
+ }
+
+ if (!$this->_errorOccurred) // if no error occurred
+ {
+ // Move the extracted extension from the temporary directory to the extensions install directory
+ $this->_moveExtension($extensionJson->name);
+ }
+
+ if (!$this->_errorOccurred) // if no error occurred
+ {
+ // Create the symlinks to the installed extension
+ $this->_createSymLinks($extensionJson->name);
+ }
+ }
+ else
+ {
+ $this->_errorOccurred = true;
+ }
+ }
+ else
+ {
+ $this->_errorOccurred = true;
+ }
+
+ if ($this->_errorOccurred === false) // if no errors occurred
+ {
+ if (!$this->_rrm($uploadData->fullPath)) // removes uploaded file
+ {
+ $this->_printInfo('Error while cleaning upload directory. Not a blocking error');
+ }
+
+ $this->_printMessage('Extension correctly installed, you can safely close this page');
+ }
+ else
+ {
+ $this->_printError('There was a blocking error while installing/updating an extension, rolling back');
+
+ $this->_rollback($uploadData, $extensionDB, $extensionJson); // rock & rollback!
+ }
+ }
+
+ /**
+ * Delete an installed extension using the extension_id stored in the DB
+ */
+ public function delExtension($extensionId)
+ {
+ $delExtension = false;
+
+ // Loads data about this extension from the DB
+ $result = $this->ci->ExtensionsModel->load($extensionId);
+ if (hasData($result)) // if something was found
+ {
+ $extensionName = $result->retval[0]->name; // extension name
+ $this->_delSoftLinks($extensionName); // not to be checked, could fail if the extension is disabled
+ // remove the extension from the extensions installation directory
+ $delExtension = $this->_rrm(ExtensionsLib::EXTENSIONS_PATH.$extensionName);
+
+ // Select all the version of this extension
+ $this->ci->ExtensionsModel->addSelect('extension_id');
+ $result = $this->ci->ExtensionsModel->loadWhere(array('name' => $extensionName));
+ if (hasData($result)) // if something was found
+ {
+ $extsArray = array();
+ foreach ($result->retval as $key => $extension) // loops on them
+ {
+ // Remove them all
+ $result = $this->ci->ExtensionsModel->delete($extension->extension_id);
+ if (isSuccess($result))
+ {
+ $delExtension = true;
+ }
+ }
+ }
+ }
+
+ return $delExtension;
+ }
+
+ /**
+ * Retrive the list of all the installed extensions
+ */
+ public function getInstalledExtensions()
+ {
+ return $this->ci->ExtensionsModel->getInstalledExtensions();
+ }
+
+ /**
+ * To enable an extension
+ */
+ public function enableExtension($extensionId)
+ {
+ return $this->_toggleExtension($extensionId, true);
+ }
+
+ /**
+ * To disable an extension
+ */
+ public function disableExtension($extensionId)
+ {
+ return $this->_toggleExtension($extensionId, false);
+ }
+
+ // -------------------------------------------------------------------------------------------------
+ // Private methods
+
+ /**
+ * Loads the upload library of CI
+ */
+ private function _loadUploadLibrary()
+ {
+ $this->ci->load->library(
+ 'upload',
+ array(
+ 'upload_path' => ExtensionsLib::UPLOAD_PATH,
+ 'allowed_types' => '*',
+ 'overwrite' => true
+ )
+ );
+ }
+
+ /**
+ * Perform the upload of an extension archive and returns its data
+ */
+ private function _uploadExtension()
+ {
+ $_uploadExtension = null;
+
+ $this->_printStart('Uploading extension');
+
+ // If the upload was a success
+ if ($this->ci->upload->do_upload(ExtensionsLib::FILE_INPUT_NAME))
+ {
+ $uploadData = $this->ci->upload->data(); // retrives data about the uploaded file
+ // Checks the file extension
+ $uploadedFileExtension = '.'.pathinfo($uploadData['full_path'], PATHINFO_EXTENSION);
+ if (!in_array($uploadedFileExtension, ExtensionsLib::ARCHIVE_EXTENSIONS))
+ {
+ $this->_printFailure('file extension must be tgz OR tbz2');
+
+ // Remove the uploaded file
+ if (isset($uploadData['full_path']) && file_exists($uploadData['full_path']))
+ {
+ $this->_rrm($uploadData['full_path']);
+ }
+ }
+ else
+ {
+ // Returns the extension name and the full path of the uploaded file
+ $_uploadExtension = new stdClass();
+ $_uploadExtension->extensionName = str_replace(ExtensionsLib::ARCHIVE_EXTENSIONS, '', $uploadData['file_name']);
+ $_uploadExtension->fullPath = $uploadData['full_path'];
+ }
+ }
+ else
+ {
+ $this->_printFailure($this->ci->upload->display_errors('', ''));
+ }
+
+ $this->_printSuccess($_uploadExtension != null);
+
+ $this->_printEnd();
+
+ return $_uploadExtension;
+ }
+
+ /**
+ * To extract the extension archive
+ */
+ private function _extractExtension($uploadPath)
+ {
+ $this->_printStart('Extracting extension');
+
+ try
+ {
+ // Extracts the uploaded file
+ $pd = new PharData($uploadPath);
+
+ $pd->extractTo(ExtensionsLib::UPLOAD_PATH, null, true);
+ }
+ catch (UnexpectedValueException $uva)
+ {
+ $this->_errorOccurred = true;
+ $this->_printFailure('provided an invalid archive');
+ }
+ catch (PharException $pe)
+ {
+ $this->_errorOccurred = true;
+ $this->_printFailure('generic error occurred, check logs');
+ }
+
+ $this->_printSuccess(!$this->_errorOccurred);
+
+ $this->_printEnd();
+ }
+
+ /**
+ * Loads any previous installations of the given extension from DB
+ */
+ private function _loadPreviousInstallation($extensionName)
+ {
+ $extensionDB = null;
+
+ $this->_printStart('Loads any previous installation data');
+
+ // Loads the last version of the previous installation of this extension
+ $this->ci->ExtensionsModel->addOrder('version', 'DESC');
+ $this->ci->ExtensionsModel->addLimit(1);
+ $result = $this->ci->ExtensionsModel->loadWhere(array('name' => $extensionName));
+ if (isError($result))
+ {
+ $this->_errorOccurred = true;
+ $this->_printFailure('data base error');
+ }
+ else
+ {
+ if (hasData($result)) // if found
+ {
+ $extensionDB = $result->retval[0]; // return it!
+ }
+ else
+ {
+ $this->_printMessage('not found');
+ }
+ }
+
+ $this->_printSuccess(!$this->_errorOccurred);
+
+ $this->_printEnd();
+
+ return $extensionDB;
+ }
+
+ /**
+ * Checks the structure of the extension archive
+ */
+ private function _chkFSStructure($extensionName)
+ {
+ $this->_printStart('Checking extension file system structure');
+
+ // Checks if the root directory of this archive has the same name of the extension
+ if (is_dir(ExtensionsLib::UPLOAD_PATH.$extensionName))
+ {
+ // Checks if file extension.json exists inside the uploaded archive
+ if (!file_exists(ExtensionsLib::UPLOAD_PATH.$extensionName.'/'.ExtensionsLib::EXTENSION_JSON_NAME))
+ {
+ $this->_errorOccurred = true;
+ $this->_printFailure('missing extension.json');
+ }
+ }
+ else
+ {
+ $this->_errorOccurred = true;
+ $this->_printFailure('the root directory of the archive must have the same extension name');
+ }
+
+ $this->_printSuccess(!$this->_errorOccurred);
+
+ $this->_printEnd();
+ }
+
+ /**
+ * Checks if extension.json is correct
+ */
+ private function _chkExtensionJson($extensionName, $extensionDB)
+ {
+ $this->_printStart('Parsing and checking extension.json');
+
+ // Decodes extension.json
+ $extensionJson = json_decode(
+ file_get_contents(ExtensionsLib::UPLOAD_PATH.$extensionName.'/'.ExtensionsLib::EXTENSION_JSON_NAME)
+ );
+
+ // Checks if the parameter name of the extension.json has the same value of the extension name
+ if ($extensionJson != null && isset($extensionJson->name) && $extensionJson->name == $extensionName)
+ {
+ // Checks if the parameter version of the extension.json file exists
+ if (isset($extensionJson->version))
+ {
+ $extensionJson->currentInstalledVersion = 0; // default current installed version of this extension
+
+ if ($extensionDB != null) // if no previous installation was found in DB
+ {
+ $extensionJson->extension_id = $extensionDB->extension_id; // get the extension_id from DB
+ $extensionJson->currentInstalledVersion = $extensionDB->version; // get the current installed version from DB
+
+ $this->_printMessage('Extension already installed!');
+ $this->_printMessage('Current version: '.$extensionDB->version);
+ $this->_printMessage('Version of the uploaded extension: '.$extensionJson->version);
+
+ if ($extensionJson->version == $extensionDB->version)
+ {
+ $this->_printMessage('Updating the same version!');
+ }
+ elseif ($extensionJson->version > $extensionDB->version)
+ {
+ $this->_printMessage('Updating to a new version!');
+ }
+ else // downgrade is not possible
+ {
+ $extensionJson = null;
+ $this->_printFailure('downgrade must be performed manually');
+ }
+ }
+ else
+ {
+ $this->_printMessage('Version of the uploaded extension: '.$extensionJson->version);
+ }
+
+ // If no errors occurred
+ if ($extensionJson != null)
+ {
+ require_once('version.php'); // get the core version
+ // Checks if the required core version of the extension is the same of this system
+ if (isset($extensionJson->core_version) && $extensionJson->core_version == $fhcomplete_version)
+ {
+ $this->_printMessage('Required core version: '.$extensionJson->core_version);
+ $this->_printMessage('Current core version: '.$fhcomplete_version);
+
+ // Checks parameter dependencies of the extension.json
+ if (isset($extensionJson->dependencies)
+ && is_array($extensionJson->dependencies)
+ && count($extensionJson->dependencies) > 0)
+ {
+ // Gets the required dependencies
+ $result = $this->ci->ExtensionsModel->getDependencies($extensionJson->dependencies);
+ // If they are matcheds
+ if (hasData($result) && count($result->retval) == count($extensionJson->dependencies))
+ {
+ if (isset($extensionJson->dependencies))
+ {
+ $extensionJson->dependencies = str_replace('[', '{', json_encode($extensionJson->dependencies));
+ $extensionJson->dependencies = str_replace(']', '}', $extensionJson->dependencies);
+
+ $this->_printMessage('Required dependencies: '.$extensionJson->dependencies);
+ }
+ else
+ {
+ $extensionJson->dependencies = '';
+
+ $this->_printMessage('No dependencies are required');
+ }
+ }
+ else // Otherwise not to be installed
+ {
+ $extensionJson = null;
+ $this->_printFailure('dependencies are missing, install them to proceed');
+ }
+ }
+ // Malformed dependencies parameter
+ elseif (isset($extensionJson->dependencies) && !is_array($extensionJson->dependencies))
+ {
+ $extensionJson = null;
+ $this->_printFailure('dependencies parameter must be an array');
+ }
+ // No dependencies required
+ elseif (!isset($extensionJson->dependencies))
+ {
+ $this->_printMessage('No dependencies are required');
+ }
+ }
+ else
+ {
+ $extensionJson = null;
+ $this->_printFailure('core_version parameter is missing or it is not equal to the versione of the core');
+ }
+ }
+ }
+ else
+ {
+ $extensionJson = null;
+ $this->_printFailure('version is missing');
+ }
+ }
+ else
+ {
+ $extensionJson = null;
+ $this->_printFailure('name is missing or not equal to extension name');
+ }
+
+ $this->_printSuccess($extensionJson != null);
+
+ $this->_printEnd();
+
+ return $extensionJson;
+ }
+
+ /**
+ * Clean any previous installations of the given archive
+ */
+ private function _cleanPreviousInstallation($extensionJson)
+ {
+ $this->_printStart('Cleaning any previous installations in DB and file system');
+
+ // If a previous installation of this extension was found
+ if (isset($extensionJson->extension_id))
+ {
+ // Off with their heads!
+ if ($this->delExtension($extensionJson->extension_id))
+ {
+ $this->_printSuccess(true);
+ }
+ else
+ {
+ $this->_printFailure('please check logs');
+ }
+ }
+ else
+ {
+ $this->_printMessage('No need to clean, no previous installations found');
+ }
+
+ $this->_printEnd();
+ }
+
+ /**
+ * Insert extension's data into the DB
+ */
+ private function _installExtension($extensionJson)
+ {
+ $this->_printStart('Adding new entry in the DB');
+
+ $result = $this->ci->ExtensionsModel->insert(
+ array(
+ 'name' => $extensionJson->name,
+ 'description' => isset($extensionJson->description) ? $extensionJson->description : null,
+ 'version' => $extensionJson->version,
+ 'license' => isset($extensionJson->license) ? $extensionJson->license : null,
+ 'url' => isset($extensionJson->url) ? $extensionJson->url : null,
+ 'core_version' => $extensionJson->core_version,
+ 'dependencies' => isset($extensionJson->dependencies) ? $extensionJson->dependencies : null
+ )
+ );
+ if (isSuccess($result))
+ {
+ $this->_printSuccess(true);
+ }
+ else
+ {
+ $this->_errorOccurred = true;
+ $this->_printFailure('error while saving extension into DB');
+ }
+
+ $this->_printEnd();
+ }
+
+ /**
+ * Loads all the SQL scripts from the extension archive and executes them
+ */
+ private function _loadSQLs($pkgSQLsPath, $extensionJson)
+ {
+ $this->_printStart('Loading and executing SQL files');
+ $this->_printInfo('WARNING: if this step will fail, the database and all the directories');
+ $this->_printInfo('have to be clean manually before install again this extension');
+
+ $startVersion = $extensionJson->currentInstalledVersion; // current installed version extension
+
+ // If the current installed version extension is less then the uploaded extension
+ if ($extensionJson->currentInstalledVersion < $extensionJson->version)
+ {
+ $startVersion++; // +1
+ }
+
+ // Loops through the versions
+ for ($sqlDir = $startVersion; $sqlDir <= $extensionJson->version; $sqlDir++)
+ {
+ // If a directory with the same value of the version is present in the sql scripts directory
+ if (($files = glob($pkgSQLsPath.'/'.$sqlDir.'/*'.ExtensionsLib::SQL_FILE_EXTENSION)) != false)
+ {
+ // Loads every sql files
+ foreach ($files as $file)
+ {
+ $sql = file_get_contents($file); // gets the entire content of the file
+
+ $this->_printMessage('Executing query:');
+ $this->_printMessage($sql);
+
+ // Try to execute that
+ if (!isSuccess($result = @$this->ci->ExtensionsModel->executeQuery($sql)))
+ {
+ $this->_errorOccurred = true;
+ $this->_printFailure(' error occurred while executing the query');
+ $this->_printInfo('Is not possible to rollback the DB changes, must be done manually');
+ break;
+ }
+ else
+ {
+ $this->_printMessage('Query result:');
+ var_dump($result->retval); // KEEP IT!!!
+ $this->ci->eprintflib->printEOL();
+ }
+ }
+ }
+ }
+
+ $this->_printSuccess(!$this->_errorOccurred);
+
+ $this->_printEnd();
+ }
+
+ /**
+ * Move the extension extracted archive from the temporary directory to the extensions install directory
+ */
+ private function _moveExtension($extensionName)
+ {
+ $this->_printStart('Moving the upload extension from upload folder to extension folder');
+
+ $this->_printMessage('Current extension directory: '.ExtensionsLib::UPLOAD_PATH.$extensionName);
+ $this->_printMessage('Directory where it will be moved: '.ExtensionsLib::EXTENSIONS_PATH.$extensionName);
+
+ if (rename(ExtensionsLib::UPLOAD_PATH.$extensionName.'/', ExtensionsLib::EXTENSIONS_PATH.$extensionName))
+ {
+ $this->_printSuccess(true);
+ }
+ else
+ {
+ $this->_errorOccurred = true;
+ $this->_printFailure('error while moving');
+ }
+
+ $this->_printEnd();
+ }
+
+ /**
+ * Creates the symlinks to the installed extension
+ * Wrapper method to check the result of the operation and to print out info
+ */
+ private function _createSymLinks($extensionName)
+ {
+ $this->_printStart('Creating symlinks');
+
+ if ($this->_addSoftLinks($extensionName))
+ {
+ $this->_printSuccess(true);
+ }
+ else
+ {
+ $this->_errorOccurred = true;
+ $this->_printFailure('error while creating sym links');
+ }
+
+ $this->_printEnd();
+ }
+
+ /**
+ * Remove all the symlinks to the installed extension
+ */
+ private function _delSoftLinks($extensionName)
+ {
+ $_delSoftLinks = false;
+
+ foreach (ExtensionsLib::SOFTLINK_TARGET_DIRECTORIES as $key => $targetDirectory)
+ {
+ if (file_exists(APPPATH.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName))
+ {
+ $_delSoftLinks = unlink(APPPATH.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName);
+ }
+ }
+
+ return $_delSoftLinks;
+ }
+
+ /**
+ * Recursive remove of a file or a directory
+ */
+ private function _rrm($dir)
+ {
+ if (!file_exists($dir))
+ {
+ return true;
+ }
+
+ if (!is_dir($dir))
+ {
+ return unlink($dir);
+ }
+
+ foreach (scandir($dir) as $item)
+ {
+ if ($item == '.' || $item == '..')
+ {
+ continue;
+ }
+
+ if (!$this->_rrm($dir.DIRECTORY_SEPARATOR.$item))
+ {
+ return false;
+ }
+ }
+
+ return rmdir($dir);
+ }
+
+ /**
+ * Creates the symlinks to the installed extension
+ */
+ private function _addSoftLinks($extensionName)
+ {
+ $_addSoftLinks = false;
+ $extensionPath = ExtensionsLib::EXTENSIONS_PATH.$extensionName.'/';
+
+ // For every target directory
+ foreach (ExtensionsLib::SOFTLINK_TARGET_DIRECTORIES as $key => $targetDirectory)
+ {
+ // If destination of the symlink does not exist
+ if (!file_exists(APPPATH.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName))
+ {
+ // If the target directory does not exist than creates that
+ if (!is_dir($extensionPath.$targetDirectory))
+ {
+ mkdir($extensionPath.$targetDirectory);
+ }
+
+ // Create the symlink
+ $_addSoftLinks = symlink(
+ $extensionPath.$targetDirectory,
+ APPPATH.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName
+ );
+ if (!$_addSoftLinks)
+ {
+ break;
+ }
+ }
+ }
+
+ return $_addSoftLinks;
+ }
+
+ /**
+ * To rollback an extension installation
+ * It will be removed all the information about the given extension from DB and file system
+ */
+ private function _rollback($uploadData, $extensionDB, $extensionJson)
+ {
+ $this->_printStart('Rolling back the installation');
+
+ $this->_printMessage('Removing the uploaded file from upload directory');
+ if ($uploadData != null && isset($uploadData->fullPath) && file_exists($uploadData->fullPath))
+ {
+ $this->_rrm($uploadData->fullPath);
+ }
+
+ $this->_printMessage('Removing the extracted data from the upload directory');
+ if ($uploadData != null
+ && isset($uploadData->extensionName)
+ && file_exists(ExtensionsLib::UPLOAD_PATH.$uploadData->extensionName))
+ {
+ $this->_rrm(ExtensionsLib::UPLOAD_PATH.$uploadData->extensionName);
+ }
+
+ // If the upload of the file is a success and the extension name is present and no previous installation were found
+ if ($uploadData != null && isset($uploadData->extensionName) && $extensionDB == null)
+ {
+ // Loads all the previous installations of this extension
+ $this->ci->ExtensionsModel->addOrder('version', 'DESC');
+ $this->ci->ExtensionsModel->addLimit(1);
+ $result = $this->ci->ExtensionsModel->loadWhere(array('name' => $uploadData->extensionName));
+ if (hasData($result)) // if found
+ {
+ // Remove them all from file system and DB
+ $this->_printMessage('Removing entries in the DB related to this extension');
+ $this->delExtension($result->retval[0]->extension_id);
+ }
+ }
+ else // otherwise
+ {
+ // Remove them all only from DB
+ if ($extensionJson != null && isset($extensionJson->extension_id))
+ {
+ $this->ci->ExtensionsModel->delete($extensionJson->extension_id);
+ }
+ }
+
+ $this->_printMessage('Rollback finished');
+
+ $this->_printEnd();
+ }
+
+ /**
+ * To enable/disable an extension
+ */
+ private function _toggleExtension($extensionId, $enabled)
+ {
+ $_toggleExtension = false;
+
+ // Loads data from DB about the given extension
+ $result = $this->ci->ExtensionsModel->load($extensionId);
+ if (hasData($result))
+ {
+ $extensionName = $result->retval[0]->name; // extension name
+
+ // If to be enabled
+ if ($enabled === true)
+ {
+ // Add the symlinks
+ $_toggleExtension = $this->_addSoftLinks($extensionName);
+ }
+ else // If to be disabled
+ {
+ // Remove all the symlinks
+ $_toggleExtension = $this->_delSoftLinks($extensionName);
+ }
+
+ if ($_toggleExtension) // if is a success
+ {
+ // Updates DB
+ $result = $this->ci->ExtensionsModel->update($extensionId, array('enabled' => $enabled));
+ if (isSuccess($result))
+ {
+ $_toggleExtension = true;
+ }
+ else // if DB update fails remove symlinks from file system
+ {
+ $this->_delSoftLinks($extensionName);
+ }
+ }
+ }
+
+ return $_toggleExtension;
+ }
+
+ /**
+ * Wrapper method to print a generic error
+ */
+ private function _printError($error)
+ {
+ $this->ci->eprintflib->printError($error);
+ }
+
+ /**
+ * Wrapper method to print an error
+ */
+ private function _printFailure($error)
+ {
+ $this->_printError('Failed: '.$error);
+ }
+
+ /**
+ * Wrapper method to print a generic message
+ */
+ private function _printMessage($message)
+ {
+ $this->ci->eprintflib->printMessage($message);
+ }
+
+ /**
+ * Wrapper method to print a success
+ */
+ private function _printSuccess($cond)
+ {
+ if ($cond === true)
+ {
+ $this->_printMessage('Success!!!');
+ }
+ }
+
+ /**
+ * Wrapper method to print info
+ */
+ private function _printInfo($info)
+ {
+ $this->ci->eprintflib->printInfo($info);
+ }
+
+ /**
+ * Wrapper method to print a start message
+ */
+ private function _printStart($startMessage)
+ {
+ $this->_printInfo('------------------------------------------------------------------------------------------');
+ $this->_printMessage($startMessage);
+ }
+
+ /**
+ * Wrapper method to print an end message
+ */
+ private function _printEnd()
+ {
+ $this->_printInfo('------------------------------------------------------------------------------------------');
+ }
+}
diff --git a/application/libraries/MailLib.php b/application/libraries/MailLib.php
old mode 100755
new mode 100644
diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php
old mode 100755
new mode 100644
diff --git a/application/libraries/MigrationLib.php b/application/libraries/MigrationLib.php
index a35cafc65..a461d7a82 100644
--- a/application/libraries/MigrationLib.php
+++ b/application/libraries/MigrationLib.php
@@ -7,173 +7,72 @@ if (! defined("BASEPATH")) exit("No direct script access allowed");
*/
class MigrationLib extends CI_Migration
{
- // Prefixes and separator for messages
- const MSG_PREFIX = "[-]";
- const INFO_PREFIX = "[I]";
- const ERROR_PREFIX = "[E]";
- const SEPARATOR = "------------------------------";
- // Console colors codes
- const ERROR_COLOR = 31;
- const INFO_COLOR = 33;
-
- const PRINT_QUERY_LEN = 60;
-
- // HTML colors names
- private $HTML_COLORS = array(31 => "red", 33 => "orange");
- // Used to set if the migration process is called via command line or via browser
- private $cli;
-
/**
* Object initialization
*/
public function __construct()
{
parent::__construct();
- $this->setCli();
+
+ // Loads EPrintfLib
+ $this->load->library('EPrintfLib');
}
-
- /**
- * Set property cli to false if the migration process is called via command line
- * otherwise to false if it's called via browser
- */
- private function setCli()
- {
- if ($this->input->is_cli_request())
- {
- $this->cli = true;
- }
- else
- {
- $this->cli = false;
- }
- }
-
- /**
- * Returns the character of end of line
- * PHP_EOL platform dependent if cli is true
- * Tag
if cli is false
- */
- private function getEOL()
- {
- if ($this->cli === true)
- {
- return PHP_EOL;
- }
- else
- {
- return "
";
- }
- }
-
- /**
- * Returns the string needed to color the output
- */
- private function getColored($color)
- {
- $colored = "%s";
-
- if (!is_null($color))
- {
- if ($this->cli === true)
- {
- $colored = "\033[".$color."m%s\033[37m";
- }
- else
- {
- $colored = "HTML_COLORS[$color]."\">%s";
- }
- }
-
- return $colored;
- }
-
- /**
- * Print a message, even colored if specified
- */
- private function _print($prefix, $text, $color = null)
- {
- printf($this->getColored($color), sprintf("%s %s".$this->getEOL(), $prefix, $text));
- }
-
- /**
- * Prints a formatted message
- */
- private function printMessage($message)
- {
- $this->_print(MigrationLib::MSG_PREFIX, $message);
- }
-
- /**
- * Prints a formatted info
- */
- private function printInfo($info)
- {
- $this->_print(MigrationLib::INFO_PREFIX, $info, MigrationLib::INFO_COLOR);
- }
-
- /**
- * Prints a formatted error
- */
- private function printError($error)
- {
- $this->_print(MigrationLib::ERROR_PREFIX, $error, MigrationLib::ERROR_COLOR);
- }
-
+
/**
* Check if a column exists in a table and schema
*/
private function columnExists($name, $schema, $table)
{
$query = sprintf("SELECT %s FROM %s.%s LIMIT 1", $name, $schema, $table);
-
+
if (@$this->db->simple_query($query))
{
return true;
}
-
+
return false;
}
-
+
/**
* Print an info about the starting of method up
*/
protected function startUP()
{
- $this->printInfo(
- sprintf("%s Start method up of class %s %s", MigrationLib::SEPARATOR, get_called_class(), MigrationLib::SEPARATOR)
+ $this->eprintflib->printInfo(
+ sprintf("%s Start method up of class %s %s", EPrintfLib::SEPARATOR, get_called_class(), EPrintfLib::SEPARATOR)
);
}
-
+
/**
* Print an info about the ending of method up
*/
protected function endUP()
{
- $this->printInfo(
- sprintf("%s End method up of class %s %s", MigrationLib::SEPARATOR, get_called_class(), MigrationLib::SEPARATOR)
+ $this->eprintflib->printInfo(
+ sprintf("%s End method up of class %s %s", EPrintfLib::SEPARATOR, get_called_class(), EPrintfLib::SEPARATOR)
);
}
-
+
/**
* Print an info about the starting of method down
*/
protected function startDown()
{
- $this->printInfo(
- sprintf("%s Start method down of class %s %s", MigrationLib::SEPARATOR, get_called_class(), MigrationLib::SEPARATOR)
+ $this->eprintflib->printInfo(
+ sprintf("%s Start method down of class %s %s", EPrintfLib::SEPARATOR, get_called_class(), EPrintfLib::SEPARATOR)
);
}
-
+
/**
* Print an info about the ending of method down
*/
protected function endDown()
{
- $this->printInfo(
- sprintf("%s End method down of class %s %s", MigrationLib::SEPARATOR, get_called_class(), MigrationLib::SEPARATOR)
+ $this->eprintflib->printInfo(
+ sprintf("%s End method down of class %s %s", EPrintfLib::SEPARATOR, get_called_class(), EPrintfLib::SEPARATOR)
);
}
-
+
/**
* Adds a column, with attributes, to a table and schema
*/
@@ -185,20 +84,20 @@ class MigrationLib extends CI_Migration
{
if ($this->dbforge->add_column($schema.'.'.$table, array($name => $definition)))
{
- $this->printMessage(sprintf("Column %s.%s.%s of type %s added", $schema, $table, $name, $definition["type"]));
+ $this->eprintflib->printMessage(sprintf("Column %s.%s.%s of type %s added", $schema, $table, $name, $definition["type"]));
}
else
{
- $this->printError(sprintf("Error while adding column %s.%s.%s of type %s", $schema, $table, $name, $definition["type"]));
+ $this->eprintflib->printError(sprintf("Error while adding column %s.%s.%s of type %s", $schema, $table, $name, $definition["type"]));
}
}
else
{
- $this->printInfo(sprintf("Column %s.%s.%s already exists", $schema, $table, $name));
+ $this->eprintflib->printInfo(sprintf("Column %s.%s.%s already exists", $schema, $table, $name));
}
}
}
-
+
/**
* Modifies a column, and its attributes, of a table and schema
*/
@@ -210,20 +109,20 @@ class MigrationLib extends CI_Migration
{
if ($this->dbforge->modify_column($schema.'.'.$table, array($name => $definition)))
{
- $this->printMessage(sprintf("Column %s.%s.%s has been modified", $schema, $table, $name));
+ $this->eprintflib->printMessage(sprintf("Column %s.%s.%s has been modified", $schema, $table, $name));
}
else
{
- $this->printError(sprintf("Error while modifying column %s.%s.%s", $schema, $table, $name));
+ $this->eprintflib->printError(sprintf("Error while modifying column %s.%s.%s", $schema, $table, $name));
}
}
else
{
- $this->printInfo(sprintf("Column %s.%s.%s doesn't exist", $schema, $table, $name));
+ $this->eprintflib->printInfo(sprintf("Column %s.%s.%s doesn't exist", $schema, $table, $name));
}
}
}
-
+
/**
* Drops a column from a table and schema
*/
@@ -233,19 +132,19 @@ class MigrationLib extends CI_Migration
{
if ($this->dbforge->drop_column($schema.'.'.$table, $field))
{
- $this->printMessage(sprintf("Column %s.%s.%s has been dropped", $schema, $table, $field));
+ $this->eprintflib->printMessage(sprintf("Column %s.%s.%s has been dropped", $schema, $table, $field));
}
else
{
- $this->printError(sprintf("Error while dropping column %s.%s.%s", $schema, $table, $field));
+ $this->eprintflib->printError(sprintf("Error while dropping column %s.%s.%s", $schema, $table, $field));
}
}
else
{
- $this->printInfo(sprintf("Column %s.%s.%s doesn't exist", $schema, $table, $field));
+ $this->eprintflib->printInfo(sprintf("Column %s.%s.%s doesn't exist", $schema, $table, $field));
}
}
-
+
/**
* Sets a column as primary key of a table and schema
*/
@@ -273,17 +172,17 @@ class MigrationLib extends CI_Migration
{
$query = sprintf("ALTER TABLE %s.%s ADD CONSTRAINT %s PRIMARY KEY (%s)", $schema, $table, $name, $fields);
}
-
+
if (@$this->db->simple_query($query))
{
- $this->printMessage(sprintf("Added primary key %s on table %s.%s", $name, $schema, $table));
+ $this->eprintflib->printMessage(sprintf("Added primary key %s on table %s.%s", $name, $schema, $table));
}
else
{
- $this->printError(sprintf("Adding primary key %s on table %s.%s", $name, $schema, $table));
+ $this->eprintflib->printError(sprintf("Adding primary key %s on table %s.%s", $name, $schema, $table));
}
}
-
+
/**
* Sets a column as foreign key of a table and schema
*/
@@ -300,17 +199,17 @@ class MigrationLib extends CI_Migration
$fieldDest,
$attributes
);
-
+
if (@$this->db->simple_query($query))
{
- $this->printMessage(sprintf("Added foreign key %s on table %s.%s", $name, $schema, $table));
+ $this->eprintflib->printMessage(sprintf("Added foreign key %s on table %s.%s", $name, $schema, $table));
}
else
{
- $this->printError(sprintf("Adding foreign key %s on table %s.%s", $name, $schema, $table));
+ $this->eprintflib->printError(sprintf("Adding foreign key %s on table %s.%s", $name, $schema, $table));
}
}
-
+
/**
* Sets a column as unique key of a table and schema
*/
@@ -338,17 +237,17 @@ class MigrationLib extends CI_Migration
{
$query = sprintf("CREATE UNIQUE INDEX %s ON %s.%s (%s)", $name, $schema, $table, $fields);
}
-
+
if (@$this->db->simple_query($query))
{
- $this->printMessage(sprintf("Added unique key %s on table %s.%s", $name, $schema, $table));
+ $this->eprintflib->printMessage(sprintf("Added unique key %s on table %s.%s", $name, $schema, $table));
}
else
{
- $this->printError(sprintf("Adding unique key %s on table %s.%s", $name, $schema, $table));
+ $this->eprintflib->printError(sprintf("Adding unique key %s on table %s.%s", $name, $schema, $table));
}
}
-
+
/**
* Grants permissions to a user on a table and schema
*/
@@ -379,7 +278,7 @@ class MigrationLib extends CI_Migration
if (@$this->db->simple_query($query))
{
- $this->printMessage(
+ $this->eprintflib->printMessage(
sprintf(
"Granted permissions %s on table %s.%s to user %s",
is_null($stringPermission) ? $permissions : $stringPermission,
@@ -391,7 +290,7 @@ class MigrationLib extends CI_Migration
}
else
{
- $this->printError(
+ $this->eprintflib->printError(
sprintf(
"Granting permissions %s on table %s.%s to user %s",
is_null($stringPermission) ? $permissions : $stringPermission,
@@ -402,24 +301,24 @@ class MigrationLib extends CI_Migration
);
}
}
-
+
/**
* Creates a table in a schema with columns
*/
protected function createTable($schema, $table, $fields)
{
$this->dbforge->add_field($fields);
-
+
if ($this->dbforge->create_table($schema.'.'.$table, true))
{
- $this->printMessage(sprintf("Table %s.%s created or existing", $schema, $table));
+ $this->eprintflib->printMessage(sprintf("Table %s.%s created or existing", $schema, $table));
}
else
{
- $this->printError(sprintf("Creating table %s.%s", $schema, $table));
+ $this->eprintflib->printError(sprintf("Creating table %s.%s", $schema, $table));
}
}
-
+
/**
* Drops a table from a schema
*/
@@ -427,62 +326,62 @@ class MigrationLib extends CI_Migration
{
if ($this->dbforge->drop_table($schema.".".$table))
{
- $this->printMessage(sprintf("Table %s.%s has been dropped", $schema, $table));
+ $this->eprintflib->printMessage(sprintf("Table %s.%s has been dropped", $schema, $table));
}
else
{
- $this->printError(sprintf("Dropping table %s.%s", $schema, $table));
+ $this->eprintflib->printError(sprintf("Dropping table %s.%s", $schema, $table));
}
}
-
+
/**
* Initializes a sequence with the max value of a column
*/
protected function initializeSequence($schemaSrc, $sequence, $schemaDst, $table, $field)
{
$query = sprintf("SELECT SETVAL('%s.%s', (SELECT MAX(%s) FROM %s.%s))", $schemaSrc, $sequence, $field, $schemaDst, $table);
-
+
if (@$this->db->simple_query($query))
{
- $this->printMessage(sprintf("Sequence %s.%s has been initialized", $schemaSrc, $sequence));
+ $this->eprintflib->printMessage(sprintf("Sequence %s.%s has been initialized", $schemaSrc, $sequence));
}
else
{
- $this->printError(sprintf("Initializing sequence %s.%s", $schemaSrc, $sequence));
+ $this->eprintflib->printError(sprintf("Initializing sequence %s.%s", $schemaSrc, $sequence));
}
}
-
+
/**
* Add comment to a column
*/
protected function addCommentToColumn($schema, $table, $field, $comment)
{
$query = sprintf("COMMENT ON COLUMN %s.%s.%s IS ?", $schema, $table, $field);
-
+
if (@$this->db->query($query, array($comment)))
{
- $this->printMessage(sprintf("Comment added to %s.%s.%s", $schema, $table, $field));
+ $this->eprintflib->printMessage(sprintf("Comment added to %s.%s.%s", $schema, $table, $field));
}
else
{
- $this->printError(sprintf("Error while adding comment to %s.%s.%s", $schema, $table, $field));
+ $this->eprintflib->printError(sprintf("Error while adding comment to %s.%s.%s", $schema, $table, $field));
}
}
-
+
/**
* Add comment to a table
*/
protected function addCommentToTable($schema, $table, $comment)
{
$query = sprintf("COMMENT ON TABLE %s.%s IS ?", $schema, $table, $field);
-
+
if (@$this->db->query($query, array($comment)))
{
- $this->printMessage(sprintf("Comment added to %s.%s", $schema, $table));
+ $this->eprintflib->printMessage(sprintf("Comment added to %s.%s", $schema, $table));
}
else
{
- $this->printError(sprintf("Error while adding comment to %s.%s", $schema, $table));
+ $this->eprintflib->printError(sprintf("Error while adding comment to %s.%s", $schema, $table));
}
}
/**
@@ -515,7 +414,7 @@ class MigrationLib extends CI_Migration
if (@$this->db->simple_query($query))
{
- $this->printMessage(
+ $this->eprintflib->printMessage(
sprintf(
"Granted permissions %s on sequence %s.%s to user %s",
is_null($stringPermission) ? $permissions : $stringPermission,
@@ -527,7 +426,7 @@ class MigrationLib extends CI_Migration
}
else
{
- $this->printError(
+ $this->eprintflib->printError(
sprintf(
"Granting permissions %s on sequence %s.%s to user %s",
is_null($stringPermission) ? $permissions : $stringPermission,
@@ -538,7 +437,7 @@ class MigrationLib extends CI_Migration
);
}
}
-
+
/**
* Executes the given query
*/
@@ -547,21 +446,21 @@ class MigrationLib extends CI_Migration
if (! @$this->db->simple_query($query))
{
$error = $this->db->error();
-
+
if (is_array($error) && isset($error["message"]))
{
- $this->printError($error["message"]);
+ $this->eprintflib->printError($error["message"]);
}
else
{
- $this->printError("Error while executing a query");
+ $this->eprintflib->printError("Error while executing a query");
}
}
-
- $this->printInfo(
+
+ $this->eprintflib->printInfo(
"Query correctly executed: ".
- substr(preg_replace("/\s+/", " ", trim($query)), 0, MigrationLib::PRINT_QUERY_LEN).
- (strlen($query) > MigrationLib::PRINT_QUERY_LEN ? "..." : "")
+ substr(preg_replace("/\s+/", " ", trim($query)), 0, EPrintfLib::PRINT_QUERY_LEN).
+ (strlen($query) > EPrintfLib::PRINT_QUERY_LEN ? "..." : "")
);
}
}
diff --git a/application/libraries/extensions/.placeholder b/application/libraries/extensions/.placeholder
new file mode 100644
index 000000000..8d1c8b69c
--- /dev/null
+++ b/application/libraries/extensions/.placeholder
@@ -0,0 +1 @@
+
diff --git a/application/libraries/index.html b/application/libraries/index.html
old mode 100755
new mode 100644
diff --git a/application/logs/index.html b/application/logs/index.html
old mode 100755
new mode 100644
diff --git a/application/models/extensions/.placeholder b/application/models/extensions/.placeholder
new file mode 100644
index 000000000..8d1c8b69c
--- /dev/null
+++ b/application/models/extensions/.placeholder
@@ -0,0 +1 @@
+
diff --git a/application/models/index.html b/application/models/index.html
old mode 100755
new mode 100644
diff --git a/application/models/organisation/Organisationseinheit_model.php b/application/models/organisation/Organisationseinheit_model.php
old mode 100755
new mode 100644
diff --git a/application/models/system/Extensions_model.php b/application/models/system/Extensions_model.php
new file mode 100644
index 000000000..c93817040
--- /dev/null
+++ b/application/models/system/Extensions_model.php
@@ -0,0 +1,56 @@
+dbTable = 'system.tbl_extensions';
+ $this->pk = 'extension_id';
+ }
+
+ /**
+ * getDependencies
+ */
+ public function getDependencies($dependencies)
+ {
+ if (isError($ent = $this->isEntitled($this->dbTable, PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR))) return $ent;
+
+ return $this->execQuery(
+ 'SELECT *
+ FROM '.$this->dbTable.'
+ WHERE enabled = TRUE
+ AND name IN ?',
+ array('name' => $dependencies)
+ );
+ }
+
+ /**
+ *
+ */
+ public function getInstalledExtensions()
+ {
+ $query = 'SELECT extension_id, e1.name, e1.version, description, license, url, core_version, dependencies, enabled
+ FROM system.tbl_extensions e1
+ INNER JOIN (
+ SELECT name, MAX(version) AS version
+ FROM system.tbl_extensions
+ GROUP BY name) e2
+ ON (e1.name = e2.name AND e1.version = e2.version)';
+
+ return $this->execQuery($query);
+ }
+
+ /**
+ *
+ */
+ public function executeQuery($sql)
+ {
+ if (isError($ent = $this->isEntitled($this->dbTable, PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR))) return $ent;
+
+ return $this->execQuery($sql);
+ }
+}
diff --git a/application/models/system/MessageToken_model.php b/application/models/system/MessageToken_model.php
old mode 100755
new mode 100644
index 6d808e792..8c31a0807
--- a/application/models/system/MessageToken_model.php
+++ b/application/models/system/MessageToken_model.php
@@ -47,7 +47,7 @@ class MessageToken_model extends CI_Model
LIMIT 1';
$result = $this->db->query($sql, array(MSG_STATUS_DELETED, $token));
-
+
// If no errors occurred
if ($result)
{
@@ -58,7 +58,7 @@ class MessageToken_model extends CI_Model
return error($this->db->error());
}
}
-
+
/**
* Set the status of a message to read. If the status of the message
* is already read then update updateamum
@@ -82,9 +82,9 @@ class MessageToken_model extends CI_Model
) s ON (r.message_id = s.message_id AND r.person_id = s.person_id)
WHERE r.token = ?
LIMIT 1';
-
+
$msgs = $this->db->query($sql, array(MSG_STATUS_ARCHIVED, $token));
-
+
// If no errors occurred
if ($msgs)
{
@@ -92,9 +92,9 @@ class MessageToken_model extends CI_Model
if (count($msgs->result()) > 0)
{
$msg = $msgs->result()[0];
-
+
$msgStatusResult = false; // pessimistic expectation
-
+
// If the status of the message is unread
if ($msg->status == MSG_STATUS_UNREAD)
{
@@ -118,31 +118,31 @@ class MessageToken_model extends CI_Model
{
// Update updateamum to current date
$this->db->set('updateamum', 'NOW()');
-
+
$this->db->where('message_id', $msg->message_id);
$this->db->where('person_id', $msg->receiver_id);
$this->db->where('status', MSG_STATUS_READ);
-
+
$msgStatusResult = $this->db->update('public.tbl_msg_status');
}
-
+
// If some of the previous DB manipulation (update or insert) has failed
if (!$msgStatusResult)
{
return error($this->db->error());
}
}
-
+
return success($msgs->result());
}
else
{
return error($this->db->error());
}
-
+
return success($result->result());
}
-
+
/**
* Get data of the message sender
*/
@@ -159,9 +159,9 @@ class MessageToken_model extends CI_Model
LEFT JOIN public.tbl_benutzer b USING(person_id)
LEFT JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid)
WHERE p.person_id = ?';
-
+
$result = $this->db->query($sql, array($person_id));
-
+
// If no errors occurred
if ($result)
{
@@ -172,9 +172,9 @@ class MessageToken_model extends CI_Model
return error($this->db->error());
}
}
-
+
/**
- *
+ *
*/
public function isEmployee($person_id)
{
@@ -184,9 +184,9 @@ class MessageToken_model extends CI_Model
LEFT JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid)
WHERE p.person_id = ?
AND b.aktiv = TRUE';
-
+
$result = $this->db->query($sql, array($person_id));
-
+
// If no errors occurred
if ($result)
{
@@ -194,14 +194,14 @@ class MessageToken_model extends CI_Model
if (is_array($result->result()) && count($result->result()) > 0)
{
$person = $result->result()[0];
-
+
// If it is an employee
if ($person->mitarbeiter_uid != null)
{
return true;
}
}
-
+
return false;
}
else
@@ -209,4 +209,31 @@ class MessageToken_model extends CI_Model
return error($this->db->error());
}
}
-}
\ No newline at end of file
+
+ /**
+ * getRoot - Get the root of the organisation unit tree which belongs the given organisation unit parameter
+ */
+ public function getOERoot($oe_kurzbz)
+ {
+ $sql = 'SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit WHERE oe_kurzbz = ?';
+
+ $result = $this->db->query($sql, array($oe_kurzbz));
+ if ($result) // If no errors occurred
+ {
+ // If data are present
+ if (is_array($result->result()) && count($result->result()) > 0)
+ {
+ $organisationseinheit = $result->result()[0];
+
+ // If this organisationseinheit has a parent
+ if ($organisationseinheit->oe_parent_kurzbz != null)
+ {
+ // looks for the parent
+ $result = $this->getOERoot($organisationseinheit->oe_parent_kurzbz);
+ }
+ }
+ }
+
+ return $result;
+ }
+}
diff --git a/application/third_party/index.html b/application/third_party/index.html
old mode 100755
new mode 100644
diff --git a/application/tmp/.placeholder b/application/tmp/.placeholder
new file mode 100644
index 000000000..e69de29bb
diff --git a/application/views/errors/cli/error_404.php b/application/views/errors/cli/error_404.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/cli/error_db.php b/application/views/errors/cli/error_db.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/cli/error_exception.php b/application/views/errors/cli/error_exception.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/cli/error_general.php b/application/views/errors/cli/error_general.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/cli/error_php.php b/application/views/errors/cli/error_php.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/cli/index.html b/application/views/errors/cli/index.html
old mode 100755
new mode 100644
diff --git a/application/views/errors/html/error_404.php b/application/views/errors/html/error_404.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/html/error_db.php b/application/views/errors/html/error_db.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/html/error_exception.php b/application/views/errors/html/error_exception.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/html/error_general.php b/application/views/errors/html/error_general.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/html/error_php.php b/application/views/errors/html/error_php.php
old mode 100755
new mode 100644
diff --git a/application/views/errors/html/index.html b/application/views/errors/html/index.html
old mode 100755
new mode 100644
diff --git a/application/views/errors/index.html b/application/views/errors/index.html
old mode 100755
new mode 100644
diff --git a/application/views/extensions/.placeholder b/application/views/extensions/.placeholder
new file mode 100644
index 000000000..8d1c8b69c
--- /dev/null
+++ b/application/views/extensions/.placeholder
@@ -0,0 +1 @@
+
diff --git a/application/views/index.html b/application/views/index.html
old mode 100755
new mode 100644
diff --git a/application/views/system/extensions/manager.php b/application/views/system/extensions/manager.php
new file mode 100644
index 000000000..6c48bc80a
--- /dev/null
+++ b/application/views/system/extensions/manager.php
@@ -0,0 +1,168 @@
+load->view('templates/header', array('title' => 'Extensions manager', 'jqueryV1' => true, 'tablesort' => true)); ?>
+
+
+
+
| Name | +Description | +Version | +Licence | +URL | +Minimum required Core version | +Dependes on (extensions) | +Enabled | ++ | %s | +%s | +%s | +%s | +%s | +%s | +%s | ++ + | ++ Remove + | + '; + + foreach ($extensions->retval as $key => $extension) + { + echo sprintf( + $tableRow, + $extension->name, + $extension->description, + $extension->version, + $extension->license, + $extension->url, + $extension->core_version, + count($extension->dependencies) == 0 ? 'None' : json_encode($extension->dependencies), + $extension->extension_id, + $extension->enabled === true ? 'checked' : '', + $extension->extension_id + ); + } + ?> + + +
|---|