Skip to content

Commit

Permalink
rename db connection parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrant88 committed Nov 16, 2021
1 parent 668a884 commit 370f009
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/yform.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct(array $params = [])
$this->objparams['output'] = ''; // Final output of form

// predefined dataset via sql
$this->objparams['db_connection_id'] = 1; // ID of db connection in config.yml
$this->objparams['db_id'] = 1; // ID of db connection in config.yml
$this->objparams['main_where'] = ''; // like "id=12" for db
$this->objparams['main_id'] = -1; // unique Dataset ID
$this->objparams['main_table'] = ''; // for db and unique
Expand Down Expand Up @@ -279,7 +279,7 @@ public function executeFields(): self
// 2. setValue defaults via sql_object
if ($this->objparams['getdata']) {
if (!$this->objparams['sql_object'] instanceof rex_sql) {
$this->objparams['sql_object'] = rex_sql::factory($this->objparams['db_connection_id']);
$this->objparams['sql_object'] = rex_sql::factory($this->objparams['db_id']);
$this->objparams['sql_object']->setDebug($this->objparams['debug']);
$this->objparams['sql_object']->setQuery('SELECT * from ' . $this->objparams['main_table'] . ' WHERE ' . $this->objparams['main_where']);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/yform/action/create_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function executeAction()

$table_exists = false;

$tables = rex_sql::factory($this->params['db_connection_id'])->getArray('show tables');
$tables = rex_sql::factory($this->params['db_id'])->getArray('show tables');
foreach ($tables as $table) {
if (current($table) == $table_name) {
$table_exists = true;
Expand All @@ -25,16 +25,16 @@ public function executeAction()
}

if (!$table_exists) {
rex_sql::factory($this->params['db_connection_id'])->setQuery('CREATE TABLE `' . $table_name . '` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
rex_sql::factory($this->params['db_id'])->setQuery('CREATE TABLE `' . $table_name . '` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
}

foreach (rex_sql::factory($this->params['db_connection_id'])->getArray('show columns from ' . $table_name) as $k => $v) {
foreach (rex_sql::factory($this->params['db_id'])->getArray('show columns from ' . $table_name) as $k => $v) {
$cols[] = $v['Field'];
}

foreach ($this->params['value_pool']['sql'] as $key => $value) {
if (!in_array($key, $cols)) {
rex_sql::factory($this->params['db_connection_id'])->setQuery('ALTER TABLE `' . $table_name . '` ADD `' . $key . '` TEXT NOT NULL;');
rex_sql::factory($this->params['db_id'])->setQuery('ALTER TABLE `' . $table_name . '` ADD `' . $key . '` TEXT NOT NULL;');
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/yform/action/createdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function executeAction()
$table_name = $this->getElement(2);
$table_exists = false;

$tables = rex_sql::factory($this->params['db_connection_id'])->getArray('show tables');
$tables = rex_sql::factory($this->params['db_id'])->getArray('show tables');
foreach ($tables as $table) {
if (current($table) == $table_name) {
$table_exists = true;
Expand All @@ -23,16 +23,16 @@ public function executeAction()
}

if (!$table_exists) {
rex_sql::factory($this->params['db_connection_id'])->setQuery('CREATE TABLE `' . $table_name . '` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
rex_sql::factory($this->params['db_id'])->setQuery('CREATE TABLE `' . $table_name . '` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
}

foreach (rex_sql::factory($this->params['db_connection_id'])->getArray('show columns from ' . $table_name) as $k => $v) {
foreach (rex_sql::factory($this->params['db_id'])->getArray('show columns from ' . $table_name) as $k => $v) {
$cols[] = $v['Field'];
}

foreach ($this->params['value_pool']['sql'] as $key => $value) {
if (!in_array($key, $cols)) {
rex_sql::factory($this->params['db_connection_id'])->setQuery('ALTER TABLE `' . $table_name . '` ADD `' . $key . '` TEXT NOT NULL;');
rex_sql::factory($this->params['db_id'])->setQuery('ALTER TABLE `' . $table_name . '` ADD `' . $key . '` TEXT NOT NULL;');
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/yform/action/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class rex_yform_action_db extends rex_yform_action_abstract
{
public function executeAction()
{
$sql = rex_sql::factory($this->params['db_connection_id']);
$sql = rex_sql::factory($this->params['db_id']);
$sql->setDebug($this->params['debug']);

if (!$main_table = $this->getElement(2)) {
Expand Down Expand Up @@ -57,7 +57,7 @@ public function executeAction()
$action = 'update';

if ($this->params['main_id'] <= 0) {
$sql_id = rex_sql::factory($this->params['db_connection_id']);
$sql_id = rex_sql::factory($this->params['db_id']);
$sql_id->setTable($main_table);
$sql_id->setWhere($where);
$sql_id->select('id');
Expand Down
2 changes: 1 addition & 1 deletion lib/yform/action/db_query.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function executeAction()
}

try {
$sql = rex_sql::factory($this->params['db_connection_id']);
$sql = rex_sql::factory($this->params['db_id']);
$sql->setDebug($this->params['debug']);

$params = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/yform/action/readtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function executeAction()
}
$value = $this->params['value_pool']['email'][$this->getElement(4)];

$gd = rex_sql::factory($this->params['db_connection_id']);
$gd = rex_sql::factory($this->params['db_id']);
if ($this->params['debug']) {
$gd->setDebug();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/yform/validate/in_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class rex_yform_validate_in_table extends rex_yform_validate_abstract
{
public function enterObject()
{
$db = rex_sql::factory($this->params['db_connection_id']);
$db = rex_sql::factory($this->params['db_id']);
$db->setDebug($this->params['debug']);

$table = $this->getElement(3);
Expand Down
2 changes: 1 addition & 1 deletion lib/yform/validate/unique.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class rex_yform_validate_unique extends rex_yform_validate_abstract
{
public function enterObject()
{
$cd = rex_sql::factory($this->params['db_connection_id']);
$cd = rex_sql::factory($this->params['db_id']);

$table = $this->params['main_table'];
if ('' != $this->getElement('table')) {
Expand Down
4 changes: 2 additions & 2 deletions lib/yform/value/choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function enterObject()
'multiple' => $this->getElement('multiple'),
'placeholder' => $this->getElement('placeholder'),
'preferred_choices' => $this->getElement('preferred_choices'),
'db_connection_id' => $this->params['db_connection_id'],
'db_id' => $this->params['db_id'],
]);

if (null === $this->getValue()) {
Expand Down Expand Up @@ -309,7 +309,7 @@ private static function createChoiceList($elements)
$choiceList = new rex_yform_choice_list($options);

if (is_string($choicesElement) && 'SELECT' == rex_sql::getQueryType($choicesElement)) {
$sql = rex_sql::factory($elements['db_connection_id']);
$sql = rex_sql::factory($elements['db_id']);
$sql->setDebug($self->getParam('debug'));
$choiceList->createListFromSqlArray(
$sql->getArray($choicesElement)
Expand Down
2 changes: 1 addition & 1 deletion lib/yform/value/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function addRelation(array &$relations, array $names)
private function getRelationValues(array $relations)
{
$table = rex_yform_manager_table::get($this->params['main_table']);
$sql = rex_sql::factory($this->params['db_connection_id']);
$sql = rex_sql::factory($this->params['db_id']);
$sql->setDebug($this->params['debug']);

foreach ($relations as $name => $sub) {
Expand Down
2 changes: 1 addition & 1 deletion lib/yform/value/mediafile.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function saveMedia($FILE, $filefolder, $extensions_array, $rex_media_cate
$RETURN['ok'] = true;
$RETURN['filename'] = $NFILENAME;

$saveSQL = rex_sql::factory($this->params['db_connection_id'])
$saveSQL = rex_sql::factory($this->params['db_id'])
->setTable(rex::getTablePrefix() . 'media')
->setValue('title', '')
->setValue('filetype', $FILETYPE)
Expand Down

0 comments on commit 370f009

Please sign in to comment.