mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-07-30 01:37:13 +02:00
Enhanced wordpress-importer compatibility
git-svn-id: https://plugins.svn.wordpress.org/postgresql-for-wordpress/trunk@547119 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
@ -22,6 +22,7 @@
|
||||
$GLOBALS['pg4wp_numrows_query'] = '';
|
||||
$GLOBALS['pg4wp_ins_table'] = '';
|
||||
$GLOBALS['pg4wp_ins_field'] = '';
|
||||
$GLOBALS['pg4wp_last_insert'] = '';
|
||||
$GLOBALS['pg4wp_connstr'] = '';
|
||||
$GLOBALS['pg4wp_conn'] = false;
|
||||
|
||||
@ -149,15 +150,26 @@
|
||||
global $wpdb;
|
||||
$ins_field = $GLOBALS['pg4wp_ins_field'];
|
||||
$table = $GLOBALS['pg4wp_ins_table'];
|
||||
$lastq = $GLOBALS['pg4wp_last_insert'];
|
||||
|
||||
$seq = $table . '_seq';
|
||||
|
||||
// Table 'term_relationships' doesn't have a sequence
|
||||
if( $table == $wpdb->term_relationships || 'post_author' == $ins_field)
|
||||
if( $table == $wpdb->term_relationships)
|
||||
{
|
||||
$sql = 'NO QUERY';
|
||||
$data = 0;
|
||||
}
|
||||
// When using WP_Import plugin, ID is defined in the query
|
||||
elseif('post_author' == $ins_field && false !== strpos($lastq,'ID'))
|
||||
{
|
||||
$sql = 'ID was in query ';
|
||||
$pattern = '/.+\'(\d+).+$/';
|
||||
preg_match($pattern, $lastq, $matches);
|
||||
$data = $matches[1];
|
||||
// We should update the sequence on the next non-INSERT query
|
||||
$GLOBALS['pg4wp_queued_query'] = "SELECT SETVAL('$seq',(SELECT MAX(\"ID\") FROM $table)+1);";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT CURRVAL('$seq')";
|
||||
@ -167,10 +179,6 @@
|
||||
$data = pg_fetch_result($res, 0, 0);
|
||||
elseif( PG4WP_DEBUG || PG4WP_ERROR_LOG)
|
||||
{
|
||||
if( PG4WP_DEBUG)
|
||||
$lastq = $GLOBALS['pg4wp_last_insert'];
|
||||
else
|
||||
$lastq = 'UNKNOWN';
|
||||
$log = '['.microtime(true)."] wpsql_insert_id() was called with '$table' and '$ins_field'".
|
||||
" and generated an error. The latest INSERT query was :\n'$lastq'\n";
|
||||
error_log( $log, 3, PG4WP_LOG.'pg4wp_errors.log');
|
||||
@ -454,8 +462,12 @@
|
||||
if(! $GLOBALS['pg4wp_ins_field'])
|
||||
$GLOBALS['pg4wp_ins_field'] = trim($match_list[4],' () ');
|
||||
}
|
||||
if( PG4WP_DEBUG)
|
||||
$GLOBALS['pg4wp_last_insert'] = $sql;
|
||||
$GLOBALS['pg4wp_last_insert'] = $sql;
|
||||
}
|
||||
elseif( isset($GLOBALS['pg4wp_queued_query']))
|
||||
{
|
||||
pg_query($GLOBALS['pg4wp_queued_query']);
|
||||
unset($GLOBALS['pg4wp_queued_query']);
|
||||
}
|
||||
|
||||
// Correct quoting for PostgreSQL 9.1+ compatibility
|
||||
|
Reference in New Issue
Block a user