Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added imexporterhelper / optimized settingshandler / added exceptions…

… for better debuging / added information to readme
  • Loading branch information...
commit 4863a11d23c8d4578de102061894f05769348e9c 1 parent 50691a2
Benjamin Boit authored
41 README.md
View
@@ -1,4 +1,19 @@
-ImExPorter - An eZpublish database content importer and exporter
+ImExPorter - Handle your eZ Publish database easier! (for mysql and innodb)
+
+# What is it all about?
+> Handling content on different environments for eZ Publish is a pain. Right, you habe the package-manager, but do you really want
+> to manually mark and unmark changed objects before you can start exporting? Is it really the answer for the problem you are facing?
+>
+> True, there is also a way in doing a mysql-dump, but this also is a manual process...
+>
+> What the ImExPorter extension does, is reading the whole database-structure and fetching each tables content to finally create
+> packed packages for each table. These packages can be imported into your database again by just running one command on cli.
+>
+> You dont need to type in your database login all the time. ImExPorter reads your database-settings directly from your eZ Publish instance.
+> The packages are a lot smaller than a mysl-dump would be and they are split, so transfering them via scp/rsync/ftp isnt a big deal.
+>
+> At the moment only the content is exported. ImExPorter requires you, to have the same table structure on each databases you import or export
+> from/to. This will be history, when a new feature dealing with this issue arrives.
# Installation
>+ Simply clone into extensions directory or add as submodule (git submodule add https://benboi@github.com/benboi/ImExPorter.git extension/imexporter)
@@ -11,5 +26,29 @@ ImExPorter - An eZpublish database content importer and exporter
>
>+ Create a directory named "export" in your projects var directory (or change it in your config file, see step before)
+# Import / Export
+>+ Go to your projets root path via cli
+>
+>+ Run: php extension/imexporter/bin/export.php
+>
+>+ The export will now be written to your configured "BckDir"
+>
+> With importing it is the other way around. Running the import.php packages from your "BckDir" will be read and imported to your db. The tables will
+> be truncated before.
+
+# Troubleshooting
+>+ ImExPorter is not finding my database-settings
+> Where do your database-settings live?
+> site-access
+> settings/override
+> extension
+>
+> The first two wont be your problem, if you configured the database in these places. If you resourced your database-settings to
+> extension (for staging/environment separation for instance) then normally Ez Publish doesn't know these in cli-environment. With
+> ImExPorter extension there is a way to get it work. Copy the configuration lines to your site-access or better settings-override
+> and configure your extension plus settings-file in the so called "ExtensionSettingsMap". You can define as many extensions as you want,
+> but ImExPorter just cares for active extensions (more precise one). If there is a match with your configuration und currently active
+> extensions, ImExPorter will try to read the database-settings from there.
+
# TODO
>+ support for creating / changing the root structure (tables etc.) using a sql file
14 classes/lib/imexportercompressor.php
View
@@ -7,6 +7,18 @@ class ImExPorterCompressor
{
/**
+ * check for zlib installed
+ * @throws Exception
+ */
+ public function __construct()
+ {
+ if(!function_exists('gzdeflate') || !function_exists('gzinflate'))
+ {
+ throw new Exception('The php-module "zlib" is not properly installed!');
+ }
+ }
+
+ /**
* compresses a table object and returns a string
* @param ImExPorterTableInterface $table
* @return string
@@ -18,6 +30,7 @@ public function compressTable(ImExPorterTableInterface $table)
$serializedTable = serialize($table);
$base64encodedTable = base64_encode($serializedTable);
+
return gzdeflate($base64encodedTable, $extensionSettings['compressionLevel']);
}
@@ -30,6 +43,7 @@ public function decompress($dumpString)
{
$uncompressedTable = gzinflate($dumpString);
$base64decodedTable = base64_decode($uncompressedTable);
+
return unserialize($base64decodedTable);
}
45 classes/lib/imexporterhelper.php
View
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * @author Benjamin Boit
+ */
+class ImExPorterHelper
+{
+
+ /**
+ * helper method for getting the projectDir
+ * @return string
+ */
+ public static function getProjectDir()
+ {
+ return substr(__DIR__, 0, strpos(__DIR__, '/extension')) . '/';
+ }
+
+ /**
+ * helper method for getting the extensionDir
+ * @return type
+ */
+ public static function getExtensionDir()
+ {
+ return self::getProjectDir() . 'extension/';
+ }
+
+ /**
+ * helper method for getting the varDir
+ * @return type
+ */
+ public static function getVarDir()
+ {
+ return self::getProjectDir() . 'var/';
+ }
+
+ /**
+ * helper method for getting the ImExPorter extension Dir
+ * @return type
+ */
+ public static function getImExPorterDir()
+ {
+ return substr(__DIR__, 0, strpos(__DIR__, '/classes/lib')) . '/';
+ }
+
+}
12 classes/lib/imexportersettingshandler.php
View
@@ -72,25 +72,25 @@ public function getExtensionDatabaseSettings()
if($extension === false)
{
- return false;
+ throw new Exception('No global database-settings and no matching extension found!');
}
$extensionSettings = $this->getExtensionSettings();
$extensionConfigFile = $extensionSettings['extensionSettingsMap'][$extension];
- $extensionConfigFilePath = './extension/' . $extension . '/' . $extensionConfigFile;
+ $extensionConfigFilePath = ImExPorterHelper::getExtensionDir() . $extension . '/' . $extensionConfigFile;
if(!is_file($extensionConfigFilePath))
{
- return false;
+ throw new Exception('Could not find database-settings anywhere!');
}
$this->ezIni = eZINI::fetchFromFile($extensionConfigFilePath);
if(!$this->ezIni->hasSection('DatabaseSettings'))
{
- return false;
+ throw new Exception('Found extension config-file given in settings, but no database configured there!');
}
-
+
return array(
'server' => $this->ezIni->variable('DatabaseSettings', 'Server'),
'user' => $this->ezIni->variable('DatabaseSettings', 'User'),
@@ -128,7 +128,7 @@ public function getExtensionSettings()
public function getFallbackExtensionSettings()
{
- $this->ezIni = eZINI::fetchFromFile('./extension/imexporter/settings/imexporter.ini');
+ $this->ezIni = eZINI::fetchFromFile(ImExPorterHelper::getImExPorterDir() . 'settings/imexporter.ini');
return array(
'compressionLevel' => $this->ezIni->variable('ImExPortSettings', 'CompressionLevel'),
Please sign in to comment.
Something went wrong with that request. Please try again.