Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a2efcff
PostgreSQL fix for PR #14272
twister65 Dec 15, 2018
24124bc
Sets and increments the last value of a sequence.
twister65 Dec 22, 2018
7ccb9d3
Add setval function
twister65 Dec 23, 2018
d1ee594
Merge with PR #14272
twister65 Dec 23, 2018
885f48c
Fix key query
twister65 Dec 23, 2018
d746469
Fix folder path
twister65 Dec 23, 2018
dca3914
Add sequence last_value accessors
twister65 Dec 23, 2018
7f5ab7e
Space review
twister65 Dec 23, 2018
be7e696
Fix text default value
twister65 Dec 27, 2018
9d7184a
Get/Set the "is_called" sequence attribute
twister65 Dec 27, 2018
37f62a3
Update postgresql.php
twister65 Dec 28, 2018
3605ad5
Update JDatabaseExporterPostgresqlTest.php
twister65 Dec 28, 2018
f76e623
Update JDatabaseExporterPostgresqlTest.php
twister65 Dec 28, 2018
d49df74
Update JDatabaseExporterPostgresqlTest.php
twister65 Dec 28, 2018
9ff132c
Add methods to the mock
twister65 Dec 29, 2018
1514ec6
Apply the changes to the class JDatabaseImporterPostgresqlTest
twister65 Dec 29, 2018
e30574f
pgsql(pdo) can only execute one query at a time.
twister65 Dec 30, 2018
57f2c61
tabulations.
twister65 Dec 30, 2018
7ef0b2c
tabulations.
twister65 Dec 30, 2018
be51ebe
space.
twister65 Dec 30, 2018
2212c5e
Add a unique constraint on a column
twister65 Jan 2, 2019
902abe2
Add the missing Key_name to the expected result.
twister65 Jan 2, 2019
deeff6c
Tabs and spaces...
twister65 Jan 2, 2019
52fdbbe
Get PDO lob stream for xml conversion
twister65 Jan 4, 2019
a72ba9c
phpcs
twister65 Jan 4, 2019
389817c
Convert PostgreSQL BLOB data.
twister65 Jan 5, 2019
a78997e
Removes MIME base64 encoding of bytea data.
twister65 Jan 5, 2019
a31babd
Update libraries/joomla/database/exporter/pgsql.php
Jan 13, 2019
25243d9
Update libraries/joomla/database/exporter/postgresql.php
Jan 13, 2019
7585356
Update libraries/joomla/database/importer.php
Jan 13, 2019
4adbdce
Update cli/exporter.php
Jan 13, 2019
9237767
Update cli/exporter.php
Jan 13, 2019
ffebf84
Update cli/exporter.php
Jan 13, 2019
1a2ce48
Apply suggestions from code review
Jan 13, 2019
aa36c13
trigger drone
zero-24 Jan 16, 2019
2676185
Apply suggestions from code review
SharkyKZ Feb 27, 2019
c87dbcf
No magic prefix for table here
twister65 Feb 27, 2019
16b235e
Replace the magic prefix
twister65 Feb 27, 2019
3b0c183
Add magic prefix to table_structure name
twister65 Mar 5, 2019
0138495
Replace prefix (pgsql)
twister65 Mar 6, 2019
324c799
Replace sequence and key names with magic prefix.
twister65 Mar 10, 2019
729cb0d
Fix drone warning.
twister65 Mar 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions cli/exporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
/**
* @package Joomla.Cli
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// We are a valid entry point.
const _JEXEC = 1;

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

// Configure error reporting to maximum for CLI output.
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Load Library language
$lang = JFactory::getLanguage();

// Try the files_joomla file in the current language (without allowing the loading of the file in the default language)
$lang->load('files_joomla.sys', JPATH_SITE, null, false, false)
// Fallback to the files_joomla file in the default language
|| $lang->load('files_joomla.sys', JPATH_SITE, null, true);

/**
* A command line cron job to export tables and data.
*
* @since __DEPLOY_VERSION__
*/
class DbExporterCli extends JApplicationCli
{
/**
* Entry point for CLI script
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function doExecute()
{
$this->out(JText::_('DbExporterCli'));
$this->out('============================');
$total_time = microtime(true);

// Import the dependencies
jimport('joomla.filesystem.file');

$tables = JFactory::getDbo()->getTableList();
$prefix = JFactory::getDbo()->getPrefix();
$exp = JFactory::getDbo()->getExporter()->withStructure();

$iall = $this->input->getString('all', null);
$ihelp = $this->input->getString('help', null);
$itable = $this->input->getString('table', null);
$imode = $this->input->getString('mode', null);
$ipath = $this->input->get('folder', null, 'folder');
$zipfile = $ipath . 'jdata_exported_' . JFactory::getDate()->format('Y-m-d') . '.zip';

if (!($itable || $iall || $ihelp))
{
if (!$ihelp)
{
$this->out('[WARNING] Missing or wrong parameters');
$this->out();
}

$this->out('Usage: php exporter.php <options>');
$this->out('php exporter.php --all dump all tables');
$this->out('php exporter.php --mode zip dump in zip format');
$this->out('php exporter.php --table <table_name> dump <table_name>');
$this->out('php exporter.php --folder <folder_path> dump in <folder_path>');

return;
}

if ($itable)
{
if (!in_array($itable, $tables))
{
$this->out('Not Found ' . $itable . '....');
$this->out();

return;
}

$tables = array($itable);
}

$zip = JArchive::getAdapter('zip');

foreach ($tables as $table)
{
if (strpos(substr($table, 0, strlen($prefix)), $prefix) !== false)
{
$task_i_time = microtime(true);
$filename = $ipath . '/' . $table . '.xml';
$this->out();
$this->out('Exporting ' . $table . '....');
$data = (string) $exp->from($table)->withData(true);

if (JFile::exists($filename))
{
JFile::delete($filename);
}

JFile::write($filename, $data);

if ($imode && $imode === 'zip')
{
$zipFilesArray[] = array('name' => $table . '.xml', 'data' => $data);
$zip->create($zipfile, $zipFilesArray);
JFile::delete($filename);
}

$this->out('Exported in ' . round(microtime(true) - $task_i_time, 3));
}
}

$this->out('Total time: ' . round(microtime(true) - $total_time, 3));
}
}

// Instantiate the application object, passing the class name to JCli::getInstance
// and use chaining to execute the application.
JApplicationCli::getInstance('DbExporterCli')->execute();
170 changes: 170 additions & 0 deletions cli/importer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php
/**
* @package Joomla.Cli
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// We are a valid entry point.
const _JEXEC = 1;

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

// Configure error reporting to maximum for CLI output.
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Load Library language
$lang = JFactory::getLanguage();

// Try the files_joomla file in the current language (without allowing the loading of the file in the default language)
$lang->load('files_joomla.sys', JPATH_SITE, null, false, false)
// Fallback to the files_joomla file in the default language
|| $lang->load('files_joomla.sys', JPATH_SITE, null, true);

/**
* A command line cron job to import tables and data.
*
* @since __DEPLOY_VERSION__
*/
class DbImporterCli extends JApplicationCli
{
/**
* Entry point for CLI script
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function doExecute()
{
$this->out(JText::_('DbImporterCli'));
$this->out('============================');
$total_time = microtime(true);

// Import the dependencies
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');

$ipath = $this->input->get('folder', null, 'folder');
$iall = $this->input->getString('all', null);
$ihelp = $this->input->getString('help', null);
$itable = $this->input->getString('table', null);
$tables = JFolder::files($ipath, '\.xml$');

if (!($itable || $iall || $ihelp))
{
if (!$ihelp)
{
$this->out('[WARNING] Missing or wrong parameters');
$this->out();
}

$this->out('Usage: php importer.php <options>');
$this->out('php importer.php --all import all files');
$this->out('php importer.php --table <table_name> import <table_name>');
$this->out('php importer.php --folder <folder_path> import from <folder_path>');

return;
}

if ($this->input->getString('table', false))
{
$tables = array($itable . '.xml');
}

$db = JFactory::getDbo();
$prefix = $db->getPrefix();

foreach ($tables as $table)
{
$task_i_time = microtime(true);
$percorso = $ipath . '/' . $table;

// Check file
if (!JFile::exists($percorso))
{
$this->out('Not Found ' . $table);

return false;
}

$table_name = str_replace('.xml', '', $table);
$this->out('Importing ' . $table_name . ' from ' . $table);

try
{
$imp = JFactory::getDbo()->getImporter()->from(JFile::read($percorso))->withStructure()->asXml();
}
catch (JDatabaseExceptionExecuting $e)
{
$this->out('Error on getImporter' . $table . ' ' . $e);

return false;
}

$this->out('Reading data from ' . $table);

try
{
$this->out('Drop ' . $table_name);
$db->dropTable($table_name, true);
}
catch (JDatabaseExceptionExecuting $e)
{
$this->out(' Error in DROP TABLE ' . $table_name . ' ' . $e);

return false;
}

try
{
$imp->mergeStructure();
}
catch (JDatabaseExceptionExecuting $e)
{
$this->out('Error on mergeStructure' . $table . ' ' . $e);

return false;
}

$this->out('Checked structure ' . $table);

try
{
$imp->importData();
}
catch (JDatabaseExceptionExecuting $e)
{
$this->out('Error on importData' . $table . ' ' . $e);

return false;
}
$this->out('Data loaded ' . $table . ' in ' . round(microtime(true) - $task_i_time, 3));
$this->out();
}

$this->out('Total time: ' . round(microtime(true) - $total_time, 3));
}
}

// Instantiate the application object, passing the class name to JCli::getInstance
// and use chaining to execute the application.
JApplicationCli::getInstance('DbImporterCli')->execute();
Loading