mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-21 17:02:19 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable/Disable DBSkel procedure
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| DBSkel is disabled by default for security reasons.
|
||||
| You should enable DBSkel whenever you intend to use DBSkel
|
||||
|
|
||||
*/
|
||||
$config['dbskel_enabled'] = false;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DBSkel mode
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is used to set the dbskel mode:
|
||||
| - dryrun: run without changing the database, useful for testing
|
||||
| - new: build a new database or if database is already present creates only new objects
|
||||
| - diff: like new, but it also remove object from database that are NOT present in configuration files
|
||||
|
|
||||
*/
|
||||
$config['dbskel_mode'] = 'dryrun';
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class DBSkel extends CLI_Controller
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->library('DBSkelLib');
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the DBSkel procedure
|
||||
*/
|
||||
public function start($step = null, $selectedDirectories = null)
|
||||
{
|
||||
// If the DBSkel procedure fails then exit with an error
|
||||
// In this way it's possible to undestand from console what is the exit status of the procedure
|
||||
$this->dbskellib->start($step, $selectedDirectories) === true ? exit(0) : exit(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
$tableArray = array(
|
||||
'tbl_aktivitaet' => array(
|
||||
'aktivitaet_kurzbz' => array(
|
||||
'comment' => 'I guess this is the PK',
|
||||
'type' => 'character varying(16)',
|
||||
'null' => false
|
||||
),
|
||||
'beschreibung' => array(
|
||||
'comment' => 'none',
|
||||
'type' => 'character varying(256)',
|
||||
'null' => false,
|
||||
'default' => "'Test string'"
|
||||
),
|
||||
'sort' => array(
|
||||
'comment' => 'nope',
|
||||
'type' => 'integer',
|
||||
'default' => 1
|
||||
),
|
||||
'oe_kurzbz' => array(
|
||||
'comment' => 'uhm',
|
||||
'type' => 'character varying(32)'
|
||||
)
|
||||
),
|
||||
'comment' => 'Timesheet SLA Activity'
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$constraintsArray = array(
|
||||
'pk_tbl_aktivitaet' => 'ALTER TABLE fue.tbl_aktivitaet ADD CONSTRAINT pk_tbl_aktivitaet PRIMARY KEY (aktivitaet_kurzbz)',
|
||||
'fk_projekt_oe' => 'ALTER TABLE fue.tbl_aktivitaet ADD CONSTRAINT fk_test FOREIGN KEY (oe_kurzbz) REFERENCES public.tbl_organisationseinheit (oe_kurzbz)',
|
||||
'uk_beschreibung' => 'ALTER TABLE fue.tbl_aktivitaet ADD CONSTRAINT uk_beschreibung UNIQUE (beschreibung)',
|
||||
'testchk' => 'ALTER TABLE fue.tbl_aktivitaet ADD CONSTRAINT testchk CHECK (sort > 0)'
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
SELECT 'Extra file' AS justatest;
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
$functionsArray = array(
|
||||
'get_highest_content_version' =>
|
||||
'CREATE OR REPLACE FUNCTION fue.get_highest_content_version(bigint) RETURNS smallint AS $$
|
||||
DECLARE i_content_id ALIAS FOR $1;
|
||||
DECLARE rec RECORD;
|
||||
BEGIN
|
||||
|
||||
SELECT INTO rec version
|
||||
FROM campus.tbl_contentsprache
|
||||
WHERE content_id = i_content_id
|
||||
ORDER BY version desc
|
||||
LIMIT 1;
|
||||
|
||||
RETURN rec.version;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;'
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
-----------------------------------------------------
|
||||
-- Revokes all privileges from all granted users
|
||||
-----------------------------------------------------
|
||||
REVOKE ALL PRIVILEGES ON SCHEMA fue FROM vilesci;
|
||||
REVOKE ALL ON ALL TABLES IN SCHEMA fue FROM vilesci;
|
||||
REVOKE ALL ON ALL SEQUENCES IN SCHEMA fue FROM vilesci;
|
||||
REVOKE ALL ON ALL FUNCTIONS IN SCHEMA fue FROM vilesci;
|
||||
|
||||
----------------------------------------------------------------------------------------------------
|
||||
-- Gives the desired privileges to the chosen users (with great power comes great responsibility!)
|
||||
----------------------------------------------------------------------------------------------------
|
||||
|
||||
-- Schema privileges
|
||||
GRANT ALL ON SCHEMA fue TO vilesci;
|
||||
GRANT USAGE ON SCHEMA fue TO web;
|
||||
GRANT USAGE ON SCHEMA fue TO wawi;
|
||||
|
||||
-- Sequences privileges
|
||||
GRANT SELECT,UPDATE ON SEQUENCE fue.seq_projekt_dokument_projekt_dokument_id TO vilesci;
|
||||
GRANT SELECT,UPDATE ON SEQUENCE fue.seq_projekt_dokument_projekt_dokument_id TO web;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Create the schema if not exists
|
||||
CREATE SCHEMA IF NOT EXISTS fue;
|
||||
-- Comment schema
|
||||
COMMENT ON SCHEMA fue IS 'Projectmanagement';
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
$sequencesArray = array(
|
||||
'seq_projekt_dokument_projekt_dokument_id' =>
|
||||
'CREATE SEQUENCE fue.seq_projekt_dokument_projekt_dokument_id
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;'
|
||||
);
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
$viewsArray = array(
|
||||
'vw_projektressourcen' =>
|
||||
'CREATE OR REPLACE VIEW fue.vw_projektressourcen (
|
||||
projekt_ressource_id,
|
||||
projekt_kurzbz,
|
||||
projektphase_id,
|
||||
projektphase,
|
||||
typ,
|
||||
ressource_id,
|
||||
ressource,
|
||||
funktion_kurzbz,
|
||||
start,
|
||||
ende,
|
||||
oe_kurzbz,
|
||||
projektbudget,
|
||||
aufwandstyp_kurzbz,
|
||||
projektphase_fk,
|
||||
phasenbudget,
|
||||
personentage,
|
||||
nummer,
|
||||
titel,
|
||||
aufwand
|
||||
)
|
||||
AS
|
||||
SELECT tpr.projekt_ressource_id,
|
||||
COALESCE(tpr.projekt_kurzbz, tpp.projekt_kurzbz) AS projekt_kurzbz,
|
||||
tpr.projektphase_id,
|
||||
tpp.bezeichnung AS projektphase,
|
||||
COALESCE(tpp.typ, \'Projekt\'::character varying) AS typ,
|
||||
tpr.ressource_id,
|
||||
tr.bezeichnung AS ressource,
|
||||
tpr.funktion_kurzbz,
|
||||
COALESCE(tpp.start, tp.beginn) AS start,
|
||||
COALESCE(tpp.ende, tp.ende) AS ende,
|
||||
tp.oe_kurzbz,
|
||||
tp.budget AS projektbudget,
|
||||
tp.aufwandstyp_kurzbz,
|
||||
tpp.projektphase_fk,
|
||||
tpp.budget AS phasenbudget,
|
||||
tpp.personentage,
|
||||
tp.nummer,
|
||||
tp.titel,
|
||||
tpr.aufwand
|
||||
FROM fue.tbl_projekt_ressource tpr
|
||||
JOIN fue.tbl_ressource tr USING (ressource_id)
|
||||
LEFT JOIN fue.tbl_projekt tp USING (projekt_kurzbz)
|
||||
LEFT JOIN fue.tbl_projektphase tpp USING (projektphase_id);'
|
||||
);
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -19,7 +19,6 @@ class CallerLib
|
||||
private static $RESOURCES_BLACK_LIST = array(
|
||||
'CallerLib', // disabled self loading
|
||||
'LogLib', // hardly usefull and virtually dangerous
|
||||
'MigrationLib', // virtually dangerous, DB manipulation
|
||||
'FilesystemLib', // virtually dangerous, direct access to file system
|
||||
'PermissionLib', // usefull?
|
||||
'PersonLogLib'
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,466 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (! defined("BASEPATH")) exit("No direct script access allowed");
|
||||
|
||||
/**
|
||||
* Utility class to be used in the database migration process
|
||||
*/
|
||||
class MigrationLib extends CI_Migration
|
||||
{
|
||||
/**
|
||||
* Object initialization
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Loads EPrintfLib
|
||||
$this->load->library('EPrintfLib');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->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->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->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->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
|
||||
*/
|
||||
protected function addColumn($schema, $table, $fields)
|
||||
{
|
||||
foreach ($fields as $name => $definition)
|
||||
{
|
||||
if (!$this->columnExists($name, $schema, $table))
|
||||
{
|
||||
if ($this->dbforge->add_column($schema.'.'.$table, array($name => $definition)))
|
||||
{
|
||||
$this->eprintflib->printMessage(sprintf("Column %s.%s.%s of type %s added", $schema, $table, $name, $definition["type"]));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printError(sprintf("Error while adding column %s.%s.%s of type %s", $schema, $table, $name, $definition["type"]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printInfo(sprintf("Column %s.%s.%s already exists", $schema, $table, $name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies a column, and its attributes, of a table and schema
|
||||
*/
|
||||
protected function modifyColumn($schema, $table, $fields)
|
||||
{
|
||||
foreach ($fields as $name => $definition)
|
||||
{
|
||||
if ($this->columnExists($name, $schema, $table))
|
||||
{
|
||||
if ($this->dbforge->modify_column($schema.'.'.$table, array($name => $definition)))
|
||||
{
|
||||
$this->eprintflib->printMessage(sprintf("Column %s.%s.%s has been modified", $schema, $table, $name));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printError(sprintf("Error while modifying column %s.%s.%s", $schema, $table, $name));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printInfo(sprintf("Column %s.%s.%s doesn't exist", $schema, $table, $name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops a column from a table and schema
|
||||
*/
|
||||
protected function dropColumn($schema, $table, $field)
|
||||
{
|
||||
if ($this->columnExists($field, $schema, $table))
|
||||
{
|
||||
if ($this->dbforge->drop_column($schema.'.'.$table, $field))
|
||||
{
|
||||
$this->eprintflib->printMessage(sprintf("Column %s.%s.%s has been dropped", $schema, $table, $field));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printError(sprintf("Error while dropping column %s.%s.%s", $schema, $table, $field));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$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
|
||||
*/
|
||||
protected function addPrimaryKey($schema, $table, $name, $fields)
|
||||
{
|
||||
$stringFields = null;
|
||||
|
||||
if (is_array($fields))
|
||||
{
|
||||
if (count($fields) > 0)
|
||||
{
|
||||
$stringFields = "";
|
||||
for ($i = 0; $i < count($fields); $i++)
|
||||
{
|
||||
$stringFields .= $fields[$i];
|
||||
if ($i != count($fields) - 1)
|
||||
{
|
||||
$stringFields .= ", ";
|
||||
}
|
||||
}
|
||||
$query = sprintf("ALTER TABLE %s.%s ADD CONSTRAINT %s PRIMARY KEY (%s)", $schema, $table, $name, $stringFields);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = sprintf("ALTER TABLE %s.%s ADD CONSTRAINT %s PRIMARY KEY (%s)", $schema, $table, $name, $fields);
|
||||
}
|
||||
|
||||
if (@$this->db->simple_query($query))
|
||||
{
|
||||
$this->eprintflib->printMessage(sprintf("Added primary key %s on table %s.%s", $name, $schema, $table));
|
||||
}
|
||||
else
|
||||
{
|
||||
$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
|
||||
*/
|
||||
protected function addForeingKey($schema, $table, $name, $field, $schemaDest, $tableDest, $fieldDest, $attributes)
|
||||
{
|
||||
$query = sprintf(
|
||||
"ALTER TABLE %s.%s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s.%s (%s) %s",
|
||||
$schema,
|
||||
$table,
|
||||
$name,
|
||||
$field,
|
||||
$schemaDest,
|
||||
$tableDest,
|
||||
$fieldDest,
|
||||
$attributes
|
||||
);
|
||||
|
||||
if (@$this->db->simple_query($query))
|
||||
{
|
||||
$this->eprintflib->printMessage(sprintf("Added foreign key %s on table %s.%s", $name, $schema, $table));
|
||||
}
|
||||
else
|
||||
{
|
||||
$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
|
||||
*/
|
||||
protected function addUniqueKey($schema, $table, $name, $fields)
|
||||
{
|
||||
$stringFields = null;
|
||||
|
||||
if (is_array($fields))
|
||||
{
|
||||
if (count($fields) > 0)
|
||||
{
|
||||
$stringFields = "";
|
||||
for ($i = 0; $i < count($fields); $i++)
|
||||
{
|
||||
$stringFields .= $fields[$i];
|
||||
if ($i != count($fields) - 1)
|
||||
{
|
||||
$stringFields .= ", ";
|
||||
}
|
||||
}
|
||||
$query = sprintf("CREATE UNIQUE INDEX %s ON %s.%s (%s)", $name, $schema, $table, $stringFields);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = sprintf("CREATE UNIQUE INDEX %s ON %s.%s (%s)", $name, $schema, $table, $fields);
|
||||
}
|
||||
|
||||
if (@$this->db->simple_query($query))
|
||||
{
|
||||
$this->eprintflib->printMessage(sprintf("Added unique key %s on table %s.%s", $name, $schema, $table));
|
||||
}
|
||||
else
|
||||
{
|
||||
$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
|
||||
*/
|
||||
protected function grantTable($permissions, $schema, $table, $user)
|
||||
{
|
||||
$stringPermission = null;
|
||||
|
||||
if (is_array($permissions))
|
||||
{
|
||||
if (count($permissions) > 0)
|
||||
{
|
||||
$stringPermission = "";
|
||||
for ($i = 0; $i < count($permissions); $i++)
|
||||
{
|
||||
$stringPermission .= $permissions[$i];
|
||||
if ($i != count($permissions) - 1)
|
||||
{
|
||||
$stringPermission .= ", ";
|
||||
}
|
||||
}
|
||||
$query = sprintf("GRANT %s ON TABLE %s.%s TO %s", $stringPermission, $schema, $table, $user);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = sprintf("GRANT %s ON TABLE %s.%s TO %s", $permissions, $schema, $table, $user);
|
||||
}
|
||||
|
||||
if (@$this->db->simple_query($query))
|
||||
{
|
||||
$this->eprintflib->printMessage(
|
||||
sprintf(
|
||||
"Granted permissions %s on table %s.%s to user %s",
|
||||
is_null($stringPermission) ? $permissions : $stringPermission,
|
||||
$schema,
|
||||
$table,
|
||||
$user
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printError(
|
||||
sprintf(
|
||||
"Granting permissions %s on table %s.%s to user %s",
|
||||
is_null($stringPermission) ? $permissions : $stringPermission,
|
||||
$schema,
|
||||
$table,
|
||||
$user
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->eprintflib->printMessage(sprintf("Table %s.%s created or existing", $schema, $table));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printError(sprintf("Creating table %s.%s", $schema, $table));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops a table from a schema
|
||||
*/
|
||||
protected function dropTable($schema, $table)
|
||||
{
|
||||
if ($this->dbforge->drop_table($schema.".".$table))
|
||||
{
|
||||
$this->eprintflib->printMessage(sprintf("Table %s.%s has been dropped", $schema, $table));
|
||||
}
|
||||
else
|
||||
{
|
||||
$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->eprintflib->printMessage(sprintf("Sequence %s.%s has been initialized", $schemaSrc, $sequence));
|
||||
}
|
||||
else
|
||||
{
|
||||
$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->eprintflib->printMessage(sprintf("Comment added to %s.%s.%s", $schema, $table, $field));
|
||||
}
|
||||
else
|
||||
{
|
||||
$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->eprintflib->printMessage(sprintf("Comment added to %s.%s", $schema, $table));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printError(sprintf("Error while adding comment to %s.%s", $schema, $table));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Grants permissions to a user on a sequence
|
||||
*/
|
||||
protected function grantSequence($permissions, $schema, $sequence, $user)
|
||||
{
|
||||
$stringPermission = null;
|
||||
|
||||
if (is_array($permissions))
|
||||
{
|
||||
if (count($permissions) > 0)
|
||||
{
|
||||
$stringPermission = "";
|
||||
for ($i = 0; $i < count($permissions); $i++)
|
||||
{
|
||||
$stringPermission .= $permissions[$i];
|
||||
if ($i != count($permissions) - 1)
|
||||
{
|
||||
$stringPermission .= ", ";
|
||||
}
|
||||
}
|
||||
$query = sprintf("GRANT %s ON SEQUENCE %s.%s TO %s", $stringPermission, $schema, $sequence, $user);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = sprintf("GRANT %s ON SEQUENCE %s.%s TO %s", $permissions, $schema, $sequence, $user);
|
||||
}
|
||||
|
||||
if (@$this->db->simple_query($query))
|
||||
{
|
||||
$this->eprintflib->printMessage(
|
||||
sprintf(
|
||||
"Granted permissions %s on sequence %s.%s to user %s",
|
||||
is_null($stringPermission) ? $permissions : $stringPermission,
|
||||
$schema,
|
||||
$sequence,
|
||||
$user
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printError(
|
||||
sprintf(
|
||||
"Granting permissions %s on sequence %s.%s to user %s",
|
||||
is_null($stringPermission) ? $permissions : $stringPermission,
|
||||
$schema,
|
||||
$sequence,
|
||||
$user
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given query
|
||||
*/
|
||||
protected function execQuery($query)
|
||||
{
|
||||
if (! @$this->db->simple_query($query))
|
||||
{
|
||||
$error = $this->db->error();
|
||||
|
||||
if (is_array($error) && isset($error["message"]))
|
||||
{
|
||||
$this->eprintflib->printError($error["message"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->eprintflib->printError("Error while executing a query");
|
||||
}
|
||||
}
|
||||
|
||||
$this->eprintflib->printInfo(
|
||||
"Query correctly executed: ".
|
||||
substr(preg_replace("/\s+/", " ", trim($query)), 0, EPrintfLib::PRINT_QUERY_LEN).
|
||||
(strlen($query) > EPrintfLib::PRINT_QUERY_LEN ? "..." : "")
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user