Permalink
Browse files

Initial import

  • Loading branch information...
1 parent e367b20 commit c89959f9f756cb323c4a4f6bf3bebd481c080d85 @lolautruche committed Aug 26, 2010
Showing with 12,017 additions and 0 deletions.
  1. +109 −0 bin/php/sqlidoimport.php
  2. +37 −0 classes/content/diffhandlers/isqlidiffhandler.php
  3. +34 −0 classes/content/diffhandlers/sqlibinaryfilediffhandler.php
  4. +39 −0 classes/content/diffhandlers/sqlidefaultdiffhandler.php
  5. +35 −0 classes/content/diffhandlers/sqliimagediffhandler.php
  6. +47 −0 classes/content/options/sqlicontentoptions.php
  7. +39 −0 classes/content/options/sqlicontentpublishoptions.php
  8. +601 −0 classes/content/sqlicontent.php
  9. +18 −0 classes/content/sqlicontentexception.php
  10. +207 −0 classes/content/sqlicontentfiedset.php
  11. +233 −0 classes/content/sqlicontentfield.php
  12. +323 −0 classes/content/sqlicontentfieldsetholder.php
  13. +330 −0 classes/content/sqlicontentpublisher.php
  14. +90 −0 classes/content/sqlicontentutils.php
  15. +15 −0 classes/exceptions/sqliimportbaseexception.php
  16. +17 −0 classes/exceptions/sqliimportconfigexception.php
  17. +17 −0 classes/exceptions/sqliimportruntimeexception.php
  18. +91 −0 classes/ezpendingactions.php
  19. +1,380 −0 classes/ezxmltext/input/handlers/sqlixmlinputparser.php
  20. +163 −0 classes/location/sqlilocation.php
  21. +18 −0 classes/location/sqlilocationexception.php
  22. +139 −0 classes/location/sqlilocationset.php
  23. +110 −0 classes/options/sqliimportoptions.php
  24. +68 −0 classes/sourcehandlers/csv/sqlicsvdoc.php
  25. +16 −0 classes/sourcehandlers/csv/sqlicsvexception.php
  26. +45 −0 classes/sourcehandlers/csv/sqlicsvoptions.php
  27. +113 −0 classes/sourcehandlers/csv/sqlicsvrow.php
  28. +268 −0 classes/sourcehandlers/csv/sqlicsvrowset.php
  29. +69 −0 classes/sourcehandlers/isqliimporthandler.php
  30. +117 −0 classes/sourcehandlers/options/sqliimporthandleroptions.php
  31. +103 −0 classes/sourcehandlers/sqliimportabstracthandler.php
  32. +146 −0 classes/sourcehandlers/sqlirssimporthandler.php
  33. +60 −0 classes/sourcehandlers/xml/sqlixmlexception.php
  34. +50 −0 classes/sourcehandlers/xml/sqlixmloptions.php
  35. +186 −0 classes/sourcehandlers/xml/sqlixmlparser.php
  36. +428 −0 classes/sqliimportfactory.php
  37. +420 −0 classes/sqliimportitem.php
  38. +158 −0 classes/sqliimportlogger.php
  39. +184 −0 classes/sqliimporttoken.php
  40. +281 −0 classes/sqliimportutils.php
  41. +287 −0 classes/sqlischeduledimport.php
  42. +22 −0 cronjobs/sqliimport_cleanup.php
  43. +83 −0 cronjobs/sqliimport_run.php
  44. +232 −0 design/admin/javascript/calendar.js
  45. +11 −0 design/admin/javascript/jscal2.js
  46. +61 −0 design/admin/javascript/lang/ca.js
  47. +61 −0 design/admin/javascript/lang/cn.js
  48. +61 −0 design/admin/javascript/lang/cz.js
  49. +61 −0 design/admin/javascript/lang/de.js
  50. +61 −0 design/admin/javascript/lang/en.js
  51. +61 −0 design/admin/javascript/lang/es.js
  52. +61 −0 design/admin/javascript/lang/fr.js
  53. +61 −0 design/admin/javascript/lang/it.js
  54. +61 −0 design/admin/javascript/lang/jp.js
  55. +61 −0 design/admin/javascript/lang/nl.js
  56. +64 −0 design/admin/javascript/lang/pl.js
  57. +61 −0 design/admin/javascript/lang/pt.js
  58. +61 −0 design/admin/javascript/lang/ro.js
  59. +61 −0 design/admin/javascript/lang/ru.js
  60. +61 −0 design/admin/javascript/lang/sv.js
  61. +82 −0 design/admin/stylesheets/border-radius.css
  62. BIN design/admin/stylesheets/gold/brushed-steel.jpg
  63. BIN design/admin/stylesheets/gold/coolbg.png
  64. +78 −0 design/admin/stylesheets/gold/gold.css
  65. BIN design/admin/stylesheets/gold/gold.jpg
  66. BIN design/admin/stylesheets/img/cool-bg-hard-inv.png
  67. BIN design/admin/stylesheets/img/cool-bg-hard.png
  68. BIN design/admin/stylesheets/img/cool-bg-inv.png
  69. BIN design/admin/stylesheets/img/cool-bg.png
  70. BIN design/admin/stylesheets/img/drop-down.gif
  71. BIN design/admin/stylesheets/img/drop-up.gif
  72. BIN design/admin/stylesheets/img/nav-left-x2.gif
  73. BIN design/admin/stylesheets/img/nav-left.gif
  74. BIN design/admin/stylesheets/img/nav-right-x2.gif
  75. BIN design/admin/stylesheets/img/nav-right.gif
  76. BIN design/admin/stylesheets/img/time-down.png
  77. BIN design/admin/stylesheets/img/time-up.png
  78. +350 −0 design/admin/stylesheets/jscal2.css
  79. +116 −0 design/admin/stylesheets/matrix/matrix.css
  80. BIN design/admin/stylesheets/matrix/nav-left-x2.gif
  81. BIN design/admin/stylesheets/matrix/nav-left.gif
  82. BIN design/admin/stylesheets/matrix/nav-right-x2.gif
  83. BIN design/admin/stylesheets/matrix/nav-right.gif
  84. +31 −0 design/admin/stylesheets/reduce-spacing.css
  85. BIN design/admin/stylesheets/shadow-b.png
  86. BIN design/admin/stylesheets/steel/brushed-steel.jpg
  87. BIN design/admin/stylesheets/steel/brushed-steel.png
  88. BIN design/admin/stylesheets/steel/coolbg.png
  89. +61 −0 design/admin/stylesheets/steel/steel.css
  90. BIN design/admin/stylesheets/steel/steel.jpg
  91. +66 −0 design/admin/stylesheets/win2k/win2k.css
  92. +72 −0 design/admin/templates/sqliimport/addimport.tpl
  93. +132 −0 design/admin/templates/sqliimport/addscheduled.tpl
  94. +4 −0 design/admin/templates/sqliimport/altererror.tpl
  95. +113 −0 design/admin/templates/sqliimport/list.tpl
  96. +16 −0 design/admin/templates/sqliimport/parts/leftmenu.tpl
  97. +112 −0 design/admin/templates/sqliimport/scheduledlist.tpl
  98. +3 −0 doc/CHANGELOG
  99. +33 −0 doc/INSTALL.txt
  100. +340 −0 doc/LICENSE
  101. +233 −0 doc/README.txt
  102. BIN doc/SQLIImport doc.pdf
  103. +229 −0 doc/fromString.txt
  104. BIN doc/images/admin_addscheduled.jpg
  105. BIN doc/images/admin_importlist.jpg
  106. BIN doc/images/sqli_logo.jpg
  107. BIN doc/uml/CSVDoc.dia
  108. BIN doc/uml/CSVDoc.png
  109. BIN doc/uml/ImportHandlers.dia
  110. BIN doc/uml/ImportHandlers.png
  111. BIN doc/uml/SQLIContent.dia
  112. BIN doc/uml/SQLIContent.png
  113. +10 −0 extension.xml
  114. +26 −0 ezinfo.php
  115. +77 −0 modules/sqliimport/addimport.php
  116. +144 −0 modules/sqliimport/addscheduled.php
  117. +80 −0 modules/sqliimport/alterimport.php
  118. +36 −0 modules/sqliimport/fatalerrorhandler.php
  119. +45 −0 modules/sqliimport/list.php
  120. +110 −0 modules/sqliimport/module.php
  121. +43 −0 modules/sqliimport/purgelist.php
  122. +66 −0 modules/sqliimport/removescheduled.php
  123. +45 −0 modules/sqliimport/scheduledlist.php
  124. +15 −0 settings/cronjob.ini.append.php
  125. +6 −0 settings/design.ini.append.php
  126. +27 −0 settings/menu.ini.append.php
  127. +7 −0 settings/module.ini.append.php
  128. +6 −0 settings/site.ini.append.php
  129. +70 −0 settings/sqliimport.ini
  130. +22 −0 settings/sqliimport.ini.append.php
  131. +30 −0 sql/mysql/schema.sql
  132. +44 −0 stubs/content.php
  133. +36 −0 stubs/contentcreate.php
  134. +21 −0 stubs/contentremove.php
  135. +41 −0 stubs/csv.php
  136. +5 −0 stubs/example.csv
  137. +21 −0 stubs/scriptinit.php
  138. +56 −0 stubs/xml.php
  139. +250 −0 translations/fre-FR/translation.ts
  140. +250 −0 translations/untranslated/translation.ts
View
@@ -0,0 +1,109 @@
+<?php
+/**
+ * Main import script
+ * @copyright Copyright (C) 2010 - SQLi Agency. All rights reserved
+ * @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
+ * @author Jerome Vieilledent
+ * @version @@@VERSION@@@
+ * @package sqliimport
+ */
+
+require 'autoload.php';
+
+$cli = eZCLI::instance();
+$cli->setUseStyles(true);
+$script = eZScript::instance( array( 'description' => ( "SQLIImport import script\n"),
+ 'use-session' => false,
+ 'use-modules' => true,
+ 'use-extensions' => true ) );
+
+$script->startup();
+
+// Options processing
+$options = $script->getOptions(
+ '[source-handlers:][list-source-handlers][options:]',
+ '',
+ array(
+ 'source-handlers' => 'Comma separated source handlers identifiers. If not provided, all source handlers will be processed.',
+ 'list-source-handlers' => 'Lists all available handlers',
+ 'options' => 'Options for import handlers. Should be something like --options="handler1::foo=bar,foo2=baz|handler2::someoption=biz"'
+ )
+);
+$script->initialize();
+$script->setUseDebugAccumulators( true );
+
+include_once 'extension/sqliimport/modules/sqliimport/fatalerrorhandler.php';
+
+try
+{
+ $importINI = eZINI::instance( 'sqliimport.ini' );
+ $aAvailableSourceHandlers = $importINI->variable( 'ImportSettings', 'AvailableSourceHandlers' );
+
+ /*
+ * List all available source handlers if requested, then exit
+ */
+ if( isset( $options['list-source-handlers'] ) )
+ {
+ if( $aAvailableSourceHandlers )
+ {
+ $cli->notice( 'Available source handlers :' );
+ $cli->warning( implode( ', ', $aAvailableSourceHandlers ) );
+ }
+ else
+ {
+ $cli->error( 'No source handler defined !' );
+ }
+ $script->shutdown();
+ }
+ else
+ {
+ /*
+ * Process requested import handlers
+ * An SQLIImportItem object will be created and stored in DB for each handler
+ */
+ $requestedHandlers = $options['source-handlers'] ? $options['source-handlers'] : '';
+ $aRequestedHandlers = $requestedHandlers ? explode( ',', $requestedHandlers ) : $importINI->variable( 'ImportSettings', 'AvailableSourceHandlers');
+ $areValidHandlers = SQLIImportFactory::checkExistingHandlers( $aRequestedHandlers ); // An exception may be thrown if a handler is not defined in sqliimport.ini
+ if( $aRequestedHandlers )
+ {
+ $aHandlersOptions = SQLIImportHandlerOptions::decodeHandlerOptionLine( $options['options'] );
+ $importUser = eZUser::fetchByName( 'admin' ); // As this is a manual script, "Admin" user will be used to import
+ $aImportItems = array();
+
+ // First stores an SQLIImportItem for each handler to process
+ foreach( $aRequestedHandlers as $handler )
+ {
+ $handlerOptions = isset( $aHandlersOptions[$handler] ) ? $aHandlersOptions[$handler] : null;
+ $pendingImport = new SQLIImportItem( array(
+ 'handler' => $handler,
+ 'user_id' => $importUser->attribute( 'contentobject_id' ),
+ ) );
+ if ( $handlerOptions instanceof SQLIImportHandlerOptions )
+ $pendingImport->setAttribute( 'options', $handlerOptions );
+ $pendingImport->store();
+ $aImportItems[] = $pendingImport;
+ }
+
+ $importFactory = SQLIImportFactory::instance();
+ $importFactory->runImport( $aImportItems );
+ $importFactory->cleanup();
+ $cli->notice( 'Import is over :)' );
+ }
+ else
+ {
+ $cli->warning( 'No import handler to process ! Check sqliimport.ini to define handlers' );
+ }
+
+ $memoryMax = memory_get_peak_usage();
+ $memoryMax = round( $memoryMax / 1024 / 1024, 2 ); // Convert in Megabytes
+ $cli->notice( 'Peak memory usage : '.$memoryMax.'M' );
+ }
+
+ $script->shutdown();
+}
+catch( Exception $e )
+{
+ $errCode = $e->getCode();
+ $errCode = $errCode != 0 ? $errCode : 1; // If an error has occured, script must terminate with a status other than 0
+ $script->shutdown( $errCode, $e->getMessage() );
+}
@@ -0,0 +1,37 @@
+<?php
+/**
+ * File containing ISQLIDiffHandler class
+ * @copyright Copyright (C) 2010 - SQLi Agency. All rights reserved
+ * @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
+ * @author Jerome Vieilledent
+ * @version @@@VERSION@@@
+ * @package sqliimport
+ * @subpackage content
+ * @subpackage diffhandlers
+ */
+
+/**
+ * Interface for diff handlers.
+ * Diff handlers are used to check if a content field really needs to be updated or not.
+ * If a content object is strictly the same, then it shouldn't be published (avoids useless time consumption).
+ * By default, datatype toString() method is used to compare input content with current content, but it can be insufficient
+ * with complex datatypes (ie. for images, binary files...).
+ * By defining a diff handler, you extend the SQLIImport content system allowing it to check for content modification more accurately.
+ *
+ * Every diff handler needs to be declared in sqliimport.ini and each declared class must implement this interface.
+ * <i>sqliimport.ini</i>
+ * <code>
+ *
+ * </code>
+ */
+interface ISQLIDiffHandler
+{
+ /**
+ * Checks if content has been really modified for $field
+ * Returns true if content has been modified, false otherwise
+ * @param string $data "New" data that needs to be compared with published data
+ * @param eZContentObjectAttribute $attribute Published attribute, for reference
+ * @return bool
+ */
+ public static function contentIsModified( $data, eZContentObjectAttribute $attribute );
+}
@@ -0,0 +1,34 @@
+<?php
+/**
+ * File containing SQLIBinaryFileDiffHandler class
+ * @copyright Copyright (C) 2010 - SQLi Agency. All rights reserved
+ * @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
+ * @author Jerome Vieilledent
+ * @version @@@VERSION@@@
+ * @package sqliimport
+ * @subpackage content
+ * @subpackage diffhandlers
+ */
+
+/**
+ * Diff handler for ezbinaryfile attributes.
+ * Only takes file name into account.
+ */
+class SQLIBinaryFileDiffHandler implements ISQLIDiffHandler
+{
+ /**
+ * (non-PHPdoc)
+ * @see extension/sqliimport/classes/content/diffhandlers/ISQLIDiffHandler::contentIsModified()
+ */
+ public static function contentIsModified( $data, eZContentObjectAttribute $attribute )
+ {
+ $isModified = false;
+
+ $originalFilename = $attribute->attribute( 'content' )->attribute( 'original_filename' );
+ $newFilename = basename( (string)$data );
+ if( $newFilename != $originalFilename )
+ $isModified = true;
+
+ return $isModified;
+ }
+}
@@ -0,0 +1,39 @@
+<?php
+/**
+ * File containing SQLIDefaultDiffHandler class
+ * @copyright Copyright (C) 2010 - SQLi Agency. All rights reserved
+ * @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
+ * @author Jerome Vieilledent
+ * @version @@@VERSION@@@
+ * @package sqliimport
+ * @subpackage content
+ * @subpackage diffhandlers
+ */
+
+/**
+ * Default diff handler for content fields.
+ * Note : It is HIGHLY RECOMMENDED for all datatypes to implement toString() methods (see eZDatatype::toString()).
+ * Attribute content will be indeed compared with toString() method or data_text field !
+ */
+class SQLIDefaultDiffHandler implements ISQLIDiffHandler
+{
+ /**
+ * (non-PHPdoc)
+ * @see extension/sqliimport/classes/content/diffhandlers/ISQLIDiffHandler::contentIsModified()
+ */
+ public static function contentIsModified( $data, eZContentObjectAttribute $attribute )
+ {
+ $isModified = false;
+
+ // Use toString() method if available from datatype, data_text otherwise
+ if( method_exists( $attribute->datatype(), 'toString' ) )
+ $attributeValue = $attribute->toString();
+ else
+ $attributeValue = $attribute->attribute( 'data_text' );
+
+ if( (string)$data != $attributeValue )
+ $isModified = true;
+
+ return $isModified;
+ }
+}
@@ -0,0 +1,35 @@
+<?php
+/**
+ * File containing SQLIImageDiffHandler class
+ * @copyright Copyright (C) 2010 - SQLi Agency. All rights reserved
+ * @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
+ * @author Jerome Vieilledent
+ * @version @@@VERSION@@@
+ * @package sqliimport
+ * @subpackage content
+ * @subpackage diffhandlers
+ */
+
+/**
+ * Diff handler for ezimage attributes.
+ * Only takes file name into account.
+ */
+class SQLIImageDiffHandler implements ISQLIDiffHandler
+{
+ /**
+ * (non-PHPdoc)
+ * @see extension/sqliimport/classes/content/diffhandlers/ISQLIDiffHandler::contentIsModified()
+ */
+ public static function contentIsModified( $data, eZContentObjectAttribute $attribute )
+ {
+ $isModified = false;
+
+ $imageHandler = $attribute->attribute( 'content' );
+ $originalFilename = $imageHandler->attribute( 'original_filename' );
+ $newImageFilename = basename( (string)$data );
+ if( $newImageFilename != $originalFilename )
+ $isModified = true;
+
+ return $isModified;
+ }
+}
@@ -0,0 +1,47 @@
+<?php
+/**
+ * SQLIContentOptions
+ * @copyright Copyright (C) 2010 - SQLi Agency. All rights reserved
+ * @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
+ * @author Jerome Vieilledent
+ * @version @@@VERSION@@@
+ * @package sqliimport
+ * @subpackage content
+ * @subpackage options
+ */
+
+/**
+ * Class containing basic options for SQLIContent
+ */
+class SQLIContentOptions extends SQLIImportOptions
+{
+ public function __construct( array $options = array() )
+ {
+ // Define some default values
+ $this->properties = array(
+ 'remote_id' => null,
+ 'section_id' => 1,
+ 'creator_id' => false,
+ 'language' => eZContentObject::defaultLanguage(),
+ 'class_identifier' => null
+ // TODO : Implement states
+ );
+
+ parent::__construct( $options );
+ }
+
+ /**
+ * Sets the option $optionName to $optionValue.
+ * Supported options for content are :
+ * - class_identifier
+ * - remote_id => ID you can define to easily retrieve an object
+ * - section_id => Section ID for object
+ * - creator_id => Object creator UserID
+ * - language => Language for object
+ * @see lib/ezc/Base/src/ezcBaseOptions::__set()
+ */
+ public function __set( $optionName, $optionValue )
+ {
+ parent::__set( $optionName, $optionValue );
+ }
+}
@@ -0,0 +1,39 @@
+<?php
+/**
+ * File containing SQLIContentPublishOptions class
+ * @copyright Copyright (C) 2010 - SQLi Agency. All rights reserved
+ * @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
+ * @author Jerome Vieilledent
+ * @version @@@VERSION@@@
+ * @package sqliimport
+ * @subpackage content.options
+ */
+
+class SQLIContentPublishOptions extends SQLIImportOptions
+{
+ /**
+ * Constructor
+ * @param array $options
+ */
+ public function __construct( array $options = array() )
+ {
+ // Define some default values
+ $this->properties = array(
+ 'parent_node_id' => null,
+ 'modification_check' => true,
+ 'copy_prev_version' => true,
+ 'update_null_field' => false, // If true, will update any field in DB, even if data is not set (null)
+ );
+
+ parent::__construct( $options );
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see lib/ezc/Base/src/ezcBaseOptions::__set()
+ */
+ public function __set( $name, $value )
+ {
+ parent::__set( $name, $value );
+ }
+}
Oops, something went wrong.

0 comments on commit c89959f

Please sign in to comment.