Skip to content

Commit

Permalink
Does some file cleaning after database connection update.
Browse files Browse the repository at this point in the history
  • Loading branch information
JB Lebrun committed Nov 15, 2017
1 parent d7bc5a7 commit 7c28923
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 138 deletions.
28 changes: 2 additions & 26 deletions engine/lib/object/ModuleLibrary.php.inc
Expand Up @@ -453,41 +453,17 @@ class ModuleLibrary {

/* execute table creation */
return $this->create_DBTable($this->_libSQLTable, $fields, $camyks->get_mysqlencodingvalue());






/* build sql query */
$sql = 'CREATE TABLE IF NOT EXISTS '.$this->_libSQLTable.' (';
$sql .= ' id BIGINT UNSIGNED NOT NULL auto_increment,';
/* add workflow version if needed */
if ( $this->_libWFVersion !== false ) {
$sql .= ' and wf_version INT UNSIGNED default 1,';
}
foreach ( $this->_libItemTypes['db'] as $n ) {
$sql .= ' '.$this->_libItems[$n]->get_databaseDescription().',';
}
/* add workflow version if needed */
if ( $this->_libWFVersion !== false ) {
$sql .= ' PRIMARY KEY(id, wf_version) )';
} else {
$sql .= ' PRIMARY KEY(id) )';
}
$sql .= ' CHARACTER SET '.$camyks->get_mysqlencodingvalue( ).'';

/* return result of sql query execution */
return $this->execute_DBQuery($sql, __LINE__);
}

/*
* delete table from database
*/
function uninstall_databaseItems() {
global $camyks;

/* build sql query */
$sql = 'drop table '.$this->_libSQLTable;

/* return result of sql query execution */
return $this->execute_DBQuery($sql, __LINE__);
}
Expand Down
51 changes: 0 additions & 51 deletions plugin/module/Admin_ContentPage/lib/ContentPage.php.inc
Expand Up @@ -681,53 +681,6 @@ class ContentPage {
*/
function install ( ) {
global $camyks;
/* create main table *
$sql = 'CREATE TABLE `admin_contentpage`(';
$sql .= ' `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,';
$sql .= ' `parent_id` BIGINT UNSIGNED NOT NULL ,';
$sql .= ' `position` INT UNSIGNED NOT NULL ,';
$sql .= ' `type` VARCHAR(16) NOT NULL,';
$sql .= ' `name` VARCHAR(128) NOT NULL ,';
$sql .= ' `active` TINYINT(4) default 1,';
$sql .= ' `secured` TINYINT(4) default 0,';
$sql .= ' `wf_version` INT default 1,';
$sql .= ' `wf_status` VARCHAR(16) NOT NULL,';
$sql .= ' `wf_cdate` BIGINT UNSIGNED default 0 ,';
$sql .= ' `wf_mdate` BIGINT UNSIGNED default 0 ,';
$sql .= ' `wf_owner` VARCHAR(32) NOT NULL,';
$sql .= ' `wf_editor` VARCHAR(32) NOT NULL,';
$sql .= ' `wf_validator` VARCHAR(32) NOT NULL,';
$sql .= ' `template` VARCHAR( 255 ) NOT NULL ,';
$sql .= ' `theme` VARCHAR( 255 ) NOT NULL ,';
$sql .= ' `homepage` TINYINT default 0 ,';
$sql .= ' `metas` TEXT default "" ,';
for ( $i=0; $i< $this->maxmodules; $i++ ) {
$sql .= '`m'.$i.'_name` VARCHAR( 255 ) NOT NULL ,';
$sql .= '`m'.$i.'_content` VARCHAR( 255 ) NOT NULL ,';
$sql .= '`m'.$i.'_theme` VARCHAR( 255 ) NOT NULL ,';
}
$sql .= 'PRIMARY KEY ( `id`, `wf_version` ) ';
$sql .= ') CHARACTER SET '.$camyks->get_mysqlencodingvalue();
if ( !($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__) ) ) {
return false;
}
/* create locale table *
$sql = 'create table `admin_contentpagelocale` (';
$sql .= ' `id` bigint unsigned not null,';
$sql .= ' `wf_version` int unsigned default 1,';
$sql .= ' `language` varchar(3) not null,';
$sql .= ' `title` varchar(255) default "",';
$sql .= ' `shorttitle` varchar(255) default "",';
$sql .= ' `keywords` text default "",';
$sql .= ' `description` text default "",';
$sql .= ' primary key ( id, wf_version, language)';
$sql .= ') character set '.$camyks->get_mysqlencodingvalue().';';
if ( !($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__) ) ) {
return false;
}

/* create master table */
$fields = array(
Expand Down Expand Up @@ -791,10 +744,6 @@ class ContentPage {
$this->homepage = 1;
$this->metas_ = '';

/* add dummy module as single displayed module
$this->modules[0] = array('name'=>'Dummy',
'content'=>'',
'theme'=>''); */
$this->locales = array();
foreach ( $camyks->site_conf['editing_languages'] as $l ) {
$this->locales[$l] = array('title'=>'', 'shorttitle'=>'', 'keywords'=>'', 'description'=>'');
Expand Down
70 changes: 29 additions & 41 deletions plugin/module/Admin_Group/lib/AdminGroup.php.inc
Expand Up @@ -50,8 +50,8 @@ class AdminGroup {
* @return boolean success
* @access private
*/
function get ( ) {
if ( $this->name == '' )
function get() {
if ($this->name == '')
return $this->initialise();
else
return $this->get_fromDatabase();
Expand All @@ -62,7 +62,7 @@ class AdminGroup {
* @return boolean success
* @access private
*/
function initialise ( ) {
function initialise() {
$this->description = '';
$this->users = array();
$this->is_new = 1;
Expand All @@ -74,11 +74,10 @@ class AdminGroup {
* @return boolean success
* @access private
*/
function save ( ) {
if ( $this->check_data() ) {
if ( $this->is_new == 1 and $this->create_toDatabase()
or $this->update_toDatabase() )
return $this->update_usersToDatabase();
function save() {
if ($this->check_data()) {
if ($this->is_new == 1 and $this->create_toDatabase() or $this->update_toDatabase())
return $this->update_usersToDatabase();
}
return false;
}
Expand All @@ -90,6 +89,7 @@ class AdminGroup {
*/
function get_fromDatabase( ) {
global $camyks;

/* build sql query */
$sql = "SELECT *";
$sql .= " FROM admin_group";
Expand All @@ -99,12 +99,12 @@ class AdminGroup {
if ( $req = $camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__ ) ) {
/* get data from database */
if ( $data = $camyks->db_conn->get_queryDataLine()) {
$this->get_fromArray( $data );
$this->is_new = 0;
return $this->get_usersFromDatabase();
$this->get_fromArray( $data );
$this->is_new = 0;
return $this->get_usersFromDatabase();
} else {
$this->initialise();
return false;
$this->initialise();
return false;
}
}
return false;
Expand All @@ -117,6 +117,7 @@ class AdminGroup {
*/
function create_toDatabase ( ) {
global $camyks;

/* build sql query */
$sql = 'INSERT INTO `admin_group` (';
$sql .= '`name`';
Expand All @@ -125,8 +126,9 @@ class AdminGroup {
$sql .= '"'.$this->name.'"';
$sql .= ',"'.addslashes($this->description).'"';
$sql .= ')';

/* return result of sql query execution */
return ( $camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__ ) );
return ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__));
}

/*
Expand All @@ -136,12 +138,14 @@ class AdminGroup {
*/
function update_toDatabase ( ) {
global $camyks;

/* build sql query */
$sql = 'UPDATE `admin_group` ';
$sql .= ' SET description="'.addslashes($this->description).'"';
$sql .= ' WHERE name="'.$this->name.'"';

/* return result of sql query execution */
return ( $camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__ ) );
return ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__));
}

/*
Expand All @@ -151,14 +155,16 @@ class AdminGroup {
*/
function delete_fromDatabase( ) {
global $camyks;

/* build sql query */
$sql = 'delete from admin_group where name="'.$this->name.'";';

/* return result of sql query execution */
if ( $camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__ ) ) {
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
/* build sql query */
$sql = 'delete from admin_user_group where group="'.$this->name.'";';
/* return result of sql query execution */
return ( $camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__ ) );
return ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__));
}
return false;
}
Expand All @@ -170,16 +176,18 @@ class AdminGroup {
*/
function get_usersFromDatabase() {
global $camyks;

/* build sql query */
$sql = 'select user';
$sql .= ' from admin_user_group';
$sql .= ' where `group`="'.$this->name.'"';

/* execute sql query */
if ( $camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__ ) ) {
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
/* get data from database */
while ( $data = $camyks->db_conn->get_queryDataLine()) {
while ($data = $camyks->db_conn->get_queryDataLine())
$this->users[] = $data['user'];
}

/* encode user list as string */
$this->users_ = implode( $this->users, ':' );
return true;
Expand All @@ -200,7 +208,7 @@ class AdminGroup {
/* build sql query */
$sql = 'delete from admin_user_group where `group`="'.$this->name.'";';
/* add new items */
if ( count($this->users) > 0 and ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__ ))) {
if (count($this->users) > 0 and ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__))) {
$isFirst = true;
$sql = 'insert into admin_user_group ( `group`, `user` ) values';
foreach ( $this->users as $u ) {
Expand Down Expand Up @@ -239,26 +247,6 @@ class AdminGroup {

return ($camyks->db_conn->create_table('admin_user_group', $fields, $camyks->get_mysqlencodingvalue(), false, array('user', 'group')));
}

/* build sql query *
$sql = 'CREATE TABLE IF NOT EXISTS `admin_group` (';
$sql .= ' `name` VARCHAR ( 32 ) NOT NULL ,';
$sql .= ' `description` VARCHAR ( 64 ) NOT NULL ,';
$sql .= ' PRIMARY KEY ( `name` ) ';
$sql .= ')';
$sql .= ' CHARACTER SET '.$camyks->get_mysqlencodingvalue( ).'';
/* execute sql query *
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__ ) ) {
$sql = 'CREATE TABLE IF NOT EXISTS `admin_user_group` (';
$sql .= ' `user` VARCHAR ( 32 ) NOT NULL ,';
$sql .= ' `group` VARCHAR ( 32 ) NOT NULL ,';
$sql .= ' PRIMARY KEY ( `user`,`group` ) ';
$sql .= ')';
$sql .= ' CHARACTER SET '.$camyks->get_mysqlencodingvalue( ).'';
/* execute sql query *
return ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror( $this, $sql, __FILE__, __LINE__ ) );
}
*/
return false;
}

Expand Down
22 changes: 2 additions & 20 deletions plugin/module/Admin_User/lib/AdminUser.php.inc
Expand Up @@ -248,25 +248,7 @@ class AdminUser {
);

if ($camyks->db_conn->create_table('admin_user', $fields, $camyks->get_mysqlencodingvalue(), false, array('login'))) {

/* build sql query *
$sql = 'CREATE TABLE `admin_user` (';
$sql .= ' `login` VARCHAR ( '.ADMINUSER_LOGIN_MAX_LENGTH.' ) BINARY NOT NULL ,';
$sql .= ' `pwd` VARCHAR ( 32 ) NOT NULL ,';
$sql .= ' `firstname` VARCHAR ( '.ADMINUSER_FIRSTNAME_LENGTH.' ) NOT NULL ,';
$sql .= ' `lastname` VARCHAR ( '.ADMINUSER_LASTNAME_LENGTH.' ) NOT NULL ,';
$sql .= ' `email` VARCHAR ( '.ADMINUSER_EMAIL_LENGTH.' ) NOT NULL ,';
$sql .= ' `active` TINYINT NOT NULL ,';
$sql .= ' `webmaster` TINYINT NOT NULL ,';
$sql .= ' `address` TEXT NOT NULL ,';
$sql .= ' `rights` TEXT NOT NULL ,';
$sql .= ' `content` TEXT NOT NULL ,';
$sql .= ' PRIMARY KEY ( `login` ) )';
$sql .= ' CHARACTER SET '.$camyks->get_mysqlencodingvalue( ).'';
/* execute sql query *
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
/* try to add first user */
/* add first user */
$this->initialise();
$this->login = $params['login'];
$this->pwd = $params['password'];
Expand All @@ -278,7 +260,7 @@ class AdminUser {
$this->change_pwd = 1;
$this->is_new = 1;
$this->rights_ = '';
/* add user */
/* save user */
return $this->save();
}
return false;
Expand Down

0 comments on commit 7c28923

Please sign in to comment.