Skip to content

Commit

Permalink
Merge pull request #24 from Opencontent/postgres
Browse files Browse the repository at this point in the history
Add postgresql support
  • Loading branch information
lolautruche committed Nov 18, 2015
2 parents bf3a81c + 7d93f5a commit 76a7cc4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 5 deletions.
8 changes: 5 additions & 3 deletions classes/sqliimportitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ public function __get( $name )
public function getOptions()
{
if ( !$this->options instanceof SQLIImportHandlerOptions && $this->attribute( 'options_serialized' ) )
$this->options = unserialize( $this->attribute( 'options_serialized' ) );

{
$this->options = SQLIImportUtils::safeUnserialize( $this->attribute( 'options_serialized' ) );
}
return $this->options;
}

Expand All @@ -175,7 +176,8 @@ public function getOptions()
public function setOptions( SQLIImportHandlerOptions $options )
{
$this->options = $options;
$this->setAttribute( 'options_serialized', serialize( $options ) );
$optionSerialized = SQLIImportUtils::safeSerialize( $options );
$this->setAttribute( 'options_serialized', $optionSerialized );
}

/**
Expand Down
19 changes: 19 additions & 0 deletions classes/sqliimportutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,23 @@ public static function viewCacheClear()
$output->outputLine();
}
}

public static function safeSerialize( $data )
{
$dataSerialized = serialize( $data );
if ( eZINI::instance()->variable( 'DatabaseSettings', 'DatabaseImplementation' ) == 'ezpostgresql' )
{
$dataSerialized = str_replace( "\0", "~~NULL_BYTE~~", $dataSerialized );
}
return $dataSerialized;
}

public static function safeUnserialize( $dataSerialized )
{
if ( eZINI::instance()->variable( 'DatabaseSettings', 'DatabaseImplementation' ) == 'ezpostgresql' )
{
$dataSerialized = str_replace( "~~NULL_BYTE~~", "\0", $dataSerialized );
}
return unserialize( $dataSerialized );
}
}
7 changes: 5 additions & 2 deletions classes/sqlischeduledimport.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public function __toString()
public function getOptions()
{
if ( !$this->options instanceof SQLIImportHandlerOptions && $this->attribute( 'options_serialized' ) )
$this->options = unserialize( $this->attribute( 'options_serialized' ) );
{
$this->options = SQLIImportUtils::safeUnserialize( $this->attribute( 'options_serialized' ) );
}
else
$this->options = new SQLIImportHandlerOptions();

Expand All @@ -151,7 +153,8 @@ public function getOptions()
public function setOptions( SQLIImportHandlerOptions $options )
{
$this->options = $options;
$this->setAttribute( 'options_serialized', serialize( $options ) );
$optionSerialized = SQLIImportUtils::safeSerialize( $options );
$this->setAttribute( 'options_serialized', $optionSerialized );
}

/**
Expand Down
50 changes: 50 additions & 0 deletions sql/postgesql/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

CREATE SEQUENCE sqliimport_item_s
START 1
INCREMENT 1
MAXVALUE 9223372036854775807
MINVALUE 1
CACHE 1;

CREATE SEQUENCE sqliimport_scheduled_s
START 1
INCREMENT 1
MAXVALUE 9223372036854775807
MINVALUE 1
CACHE 1;
CREATE TABLE sqliimport_scheduled (
id integer DEFAULT nextval('sqliimport_scheduled_s'::text) NOT NULL,
handler VARCHAR(50) DEFAULT NULL,
label VARCHAR(255) DEFAULT NULL,
options_serialized TEXT,
frequency VARCHAR(30) NOT NULL,
next INTEGER NOT NULL DEFAULT 0,
user_id INTEGER DEFAULT 0,
requested_time INTEGER DEFAULT 0,
is_active INTEGER DEFAULT 0,
manual_frequency INTEGER DEFAULT 0
);

ALTER TABLE ONLY sqliimport_scheduled ADD CONSTRAINT sqliimport_scheduled_pkey PRIMARY KEY (id);

CREATE TABLE sqliimport_item (
id INTEGER DEFAULT nextval('sqliimport_item_s'::text) NOT NULL,
handler VARCHAR(50) DEFAULT NULL,
options_serialized TEXT,
user_id INTEGER DEFAULT 0,
requested_time INTEGER DEFAULT 0,
status INTEGER DEFAULT 0,
percentage_int INTEGER DEFAULT 0,
type INTEGER DEFAULT 1,
progression_notes TEXT,
process_time INTEGER DEFAULT 0,
scheduled_id INTEGER DEFAULT 0
);

CREATE INDEX sqliimport_item_handler ON sqliimport_item USING btree (handler);
CREATE INDEX sqliimport_item_user_id ON sqliimport_item USING btree (user_id);
CREATE INDEX sqliimport_item_status ON sqliimport_item USING btree (status);
CREATE INDEX sqliimport_item_scheduled_id ON sqliimport_item USING btree (scheduled_id);
ALTER TABLE ONLY sqliimport_scheduled ADD CONSTRAINT sqliimport_scheduled_pkey PRIMARY KEY (id);


0 comments on commit 76a7cc4

Please sign in to comment.