Plugin Directory

Changeset 547119


Ignore:
Timestamp:
05/21/2012 06:06:44 PM (14 years ago)
Author:
hawk__
Message:

Enhanced wordpress-importer compatibility

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postgresql-for-wordpress/trunk/pg4wp/driver_pgsql.php

    r546732 r547119  
    2323    $GLOBALS['pg4wp_ins_table'] = '';
    2424    $GLOBALS['pg4wp_ins_field'] = '';
     25    $GLOBALS['pg4wp_last_insert'] = '';
    2526    $GLOBALS['pg4wp_connstr'] = '';
    2627    $GLOBALS['pg4wp_conn'] = false;
     
    150151        $ins_field = $GLOBALS['pg4wp_ins_field'];
    151152        $table = $GLOBALS['pg4wp_ins_table'];
     153        $lastq = $GLOBALS['pg4wp_last_insert'];
    152154       
    153155        $seq = $table . '_seq';
    154156       
    155157        // Table 'term_relationships' doesn't have a sequence
    156         if( $table == $wpdb->term_relationships || 'post_author' == $ins_field)
     158        if( $table == $wpdb->term_relationships)
    157159        {
    158160            $sql = 'NO QUERY';
    159161            $data = 0;
     162        }
     163        // When using WP_Import plugin, ID is defined in the query
     164        elseif('post_author' == $ins_field && false !== strpos($lastq,'ID'))
     165        {
     166            $sql = 'ID was in query ';
     167            $pattern = '/.+\'(\d+).+$/';
     168            preg_match($pattern, $lastq, $matches);
     169            $data = $matches[1];
     170            // We should update the sequence on the next non-INSERT query
     171            $GLOBALS['pg4wp_queued_query'] = "SELECT SETVAL('$seq',(SELECT MAX(\"ID\") FROM $table)+1);";
    160172        }
    161173        else
     
    168180            elseif( PG4WP_DEBUG || PG4WP_ERROR_LOG)
    169181            {
    170                 if( PG4WP_DEBUG)
    171                     $lastq = $GLOBALS['pg4wp_last_insert'];
    172                 else
    173                     $lastq = 'UNKNOWN';
    174182                $log = '['.microtime(true)."] wpsql_insert_id() was called with '$table' and '$ins_field'".
    175183                        " and generated an error. The latest INSERT query was :\n'$lastq'\n";
     
    455463                    $GLOBALS['pg4wp_ins_field'] = trim($match_list[4],' ()  ');
    456464            }
    457             if( PG4WP_DEBUG)
    458                 $GLOBALS['pg4wp_last_insert'] = $sql;
     465            $GLOBALS['pg4wp_last_insert'] = $sql;
     466        }
     467        elseif( isset($GLOBALS['pg4wp_queued_query']))
     468        {
     469            pg_query($GLOBALS['pg4wp_queued_query']);
     470            unset($GLOBALS['pg4wp_queued_query']);
    459471        }
    460472       
Note: See TracChangeset for help on using the changeset viewer.