diff --git a/CHANGELOG.md b/CHANGELOG.md index e9e1bc8..7aac202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,3 +12,5 @@ Changelog - Add: Param tablename - tablename for autocreation of the xPDO Package - 1.1.1 - Add: Log xPDO Package Errors in MODX Error Log +- 1.1.2 + - Add: autoPackage parameter: Package generation is executed in FormIt2db too. Before it was only active in db2FormIt. \ No newline at end of file diff --git a/_build/build.transport.php b/_build/build.transport.php index 144e855..f89614a 100644 --- a/_build/build.transport.php +++ b/_build/build.transport.php @@ -37,7 +37,7 @@ /* define package */ define('PKG_NAME', 'FormIt2db'); define('PKG_NAME_LOWER', strtolower(PKG_NAME)); -define('PKG_VERSION', '1.1.1'); +define('PKG_VERSION', '1.1.2'); define('PKG_RELEASE', 'pl'); /* define sources */ diff --git a/_build/data/properties/properties.db2formit.php b/_build/data/properties/properties.db2formit.php index 5117b70..c532420 100644 --- a/_build/data/properties/properties.db2formit.php +++ b/_build/data/properties/properties.db2formit.php @@ -123,7 +123,7 @@ 'desc' => 'prop_formit2db.autoPackage', 'type' => 'combo-boolean', 'options' => '', - 'value' => FALSE, + 'value' => false, 'lexicon' => 'formit2db:properties', ) ); diff --git a/_build/data/properties/properties.formit2db.php b/_build/data/properties/properties.formit2db.php index b0d8b14..39b63b0 100644 --- a/_build/data/properties/properties.formit2db.php +++ b/_build/data/properties/properties.formit2db.php @@ -115,7 +115,7 @@ 'desc' => 'prop_formit2db.autoPackage', 'type' => 'combo-boolean', 'options' => '', - 'value' => FALSE, + 'value' => false, 'lexicon' => 'formit2db:properties', ) ); diff --git a/core/components/formit2db/docs/changelog.txt b/core/components/formit2db/docs/changelog.txt index e9e1bc8..7aac202 100644 --- a/core/components/formit2db/docs/changelog.txt +++ b/core/components/formit2db/docs/changelog.txt @@ -12,3 +12,5 @@ Changelog - Add: Param tablename - tablename for autocreation of the xPDO Package - 1.1.1 - Add: Log xPDO Package Errors in MODX Error Log +- 1.1.2 + - Add: autoPackage parameter: Package generation is executed in FormIt2db too. Before it was only active in db2FormIt. \ No newline at end of file diff --git a/core/components/formit2db/elements/snippets/snippet.db2formit.php b/core/components/formit2db/elements/snippets/snippet.db2formit.php index e35db24..80dcf55 100644 --- a/core/components/formit2db/elements/snippets/snippet.db2formit.php +++ b/core/components/formit2db/elements/snippets/snippet.db2formit.php @@ -24,18 +24,18 @@ * @package formit2db * @subpackage db2formit snippet */ -$prefix = $modx->getOption('prefix', $scriptProperties, $modx->getOption(xPDO::OPT_TABLE_PREFIX), TRUE); -$packagename = $modx->getOption('packagename', $scriptProperties, '', TRUE); -$classname = $modx->getOption('classname', $scriptProperties, '', TRUE); -$tablename = $modx->getOption('tablename', $scriptProperties, '', TRUE); -$where = $modx->fromJson($modx->getOption('where', $scriptProperties, '', TRUE)); -$paramname = $modx->getOption('paramname', $scriptProperties, '', TRUE); -$fieldname = $modx->getOption('fieldname', $scriptProperties, $paramname, TRUE); -$arrayFormat = $modx->getOption('arrayFormat', $scriptProperties, 'csv', TRUE); -$arrayFields = $modx->fromJson($modx->getOption('arrayFields', $scriptProperties, '[]', TRUE)); -$ignoreFields = $modx->fromJson($modx->getOption('ignoreFields', $scriptProperties, '[]', TRUE)); -$notFoundRedirect = (integer)$modx->getOption('notFoundRedirect', $scriptProperties, '0', TRUE); -$autoPackage = (boolean)$modx->getOption('autoPackage', $scriptProperties, FALSE); +$prefix = $modx->getOption('prefix', $scriptProperties, $modx->getOption(xPDO::OPT_TABLE_PREFIX), true); +$packagename = $modx->getOption('packagename', $scriptProperties, '', true); +$classname = $modx->getOption('classname', $scriptProperties, '', true); +$tablename = $modx->getOption('tablename', $scriptProperties, '', true); +$where = $modx->fromJson($modx->getOption('where', $scriptProperties, '', true)); +$paramname = $modx->getOption('paramname', $scriptProperties, '', true); +$fieldname = $modx->getOption('fieldname', $scriptProperties, $paramname, true); +$arrayFormat = $modx->getOption('arrayFormat', $scriptProperties, 'csv', true); +$arrayFields = $modx->fromJson($modx->getOption('arrayFields', $scriptProperties, '[]', true)); +$ignoreFields = $modx->fromJson($modx->getOption('ignoreFields', $scriptProperties, '[]', true)); +$notFoundRedirect = (integer)$modx->getOption('notFoundRedirect', $scriptProperties, '0', true); +$autoPackage = (boolean)$modx->getOption('autoPackage', $scriptProperties, false); $packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/'); $modelpath = $packagepath . 'model/'; @@ -57,12 +57,12 @@ mkdir($schemapath, 0777); } //Use this to create a schema from an existing database - if (!$generator->writeSchema($schemafile, $packagename, 'xPDOObject', $prefix, TRUE)) { - $modx->log(modX::LOG_LEVEL_ERROR, 'Could not generate XML schema', '', 'db2formit Hook'); + if (!$generator->writeSchema($schemafile, $packagename, 'xPDOObject', $prefix, true)) { + $modx->log(modX::LOG_LEVEL_ERROR, 'Could not generate XML schema', '', 'db2FormIt Hook'); } } $generator->parseSchema($schemafile, $modelpath); - $modx->log(modX::LOG_LEVEL_WARN, 'FormIt2db autoPackage parameter active'); + $modx->log(modX::LOG_LEVEL_WARN, 'autoPackage parameter active', '', 'db2FormIt Hook'); $modx->addPackage($packagename, $modelpath, $prefix); $classname = $generator->getClassName($tablename); } else { @@ -82,8 +82,8 @@ if (!is_object($dataobject) || !($dataobject instanceof xPDOObject)) { $errorMsg = 'Failed to create object of type: ' . $classname; $hook->addError('error_message', $errorMsg); - $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'db2formit Hook'); - return FALSE; + $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'db2FormIt Hook'); + return false; } if (empty($dataobject) && $notFoundRedirect) { $modx->sendRedirect($modx->makeUrl($notFoundRedirect)); @@ -96,7 +96,7 @@ if (in_array($field, $arrayFields)) { switch ($arrayFormat) { case 'json': { - $formFields[$field] = json_decode($value, TRUE); + $formFields[$field] = json_decode($value, true); break; } case 'csv' : @@ -115,5 +115,5 @@ } } -return TRUE; +return true; ?> \ No newline at end of file diff --git a/core/components/formit2db/elements/snippets/snippet.formit2db.php b/core/components/formit2db/elements/snippets/snippet.formit2db.php index 0d21713..ee02b58 100644 --- a/core/components/formit2db/elements/snippets/snippet.formit2db.php +++ b/core/components/formit2db/elements/snippets/snippet.formit2db.php @@ -24,26 +24,48 @@ * @package formit2db * @subpackage formit2db snippet */ -$prefix = $modx->getOption('prefix', $scriptProperties, $modx->getOption(xPDO::OPT_TABLE_PREFIX), TRUE); -$packagename = $modx->getOption('packagename', $scriptProperties, '', TRUE); -$classname = $modx->getOption('classname', $scriptProperties, '', TRUE); -$tablename = $modx->getOption('tablename', $scriptProperties, '', TRUE); -$where = $modx->fromJson($modx->getOption('where', $scriptProperties, '', TRUE)); -$paramname = $modx->getOption('paramname', $scriptProperties, '', TRUE); -$fieldname = $modx->getOption('fieldname', $scriptProperties, $paramname, TRUE); -$arrayFormat = $modx->getOption('arrayFormat', $scriptProperties, 'csv', TRUE); -$arrayFields = $modx->fromJson($modx->getOption('arrayFields', $scriptProperties, '[]', TRUE)); -$removeFields = $modx->fromJson($modx->getOption('removeFields', $scriptProperties, '[]', TRUE)); -$autoPackage = (boolean)$modx->getOption('autoPackage', $scriptProperties, FALSE); +$prefix = $modx->getOption('prefix', $scriptProperties, $modx->getOption(xPDO::OPT_TABLE_PREFIX), true); +$packagename = $modx->getOption('packagename', $scriptProperties, '', true); +$classname = $modx->getOption('classname', $scriptProperties, '', true); +$tablename = $modx->getOption('tablename', $scriptProperties, '', true); +$where = $modx->fromJson($modx->getOption('where', $scriptProperties, '', true)); +$paramname = $modx->getOption('paramname', $scriptProperties, '', true); +$fieldname = $modx->getOption('fieldname', $scriptProperties, $paramname, true); +$arrayFormat = $modx->getOption('arrayFormat', $scriptProperties, 'csv', true); +$arrayFields = $modx->fromJson($modx->getOption('arrayFields', $scriptProperties, '[]', true)); +$removeFields = $modx->fromJson($modx->getOption('removeFields', $scriptProperties, '[]', true)); +$autoPackage = (boolean)$modx->getOption('autoPackage', $scriptProperties, false); $packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/'); $modelpath = $packagepath . 'model/'; -$modx->addPackage($packagename, $modelpath, $prefix); if ($autoPackage) { + $schemapath = $modelpath . 'schema/'; + $schemafile = $schemapath . $packagename . '.mysql.schema.xml'; $manager = $modx->getManager(); $generator = $manager->getGenerator(); + if (!file_exists($schemafile)) { + + if (!is_dir($packagepath)) { + mkdir($packagepath, 0777); + } + if (!is_dir($modelpath)) { + mkdir($modelpath, 0777); + } + if (!is_dir($schemapath)) { + mkdir($schemapath, 0777); + } + //Use this to create a schema from an existing database + if (!$generator->writeSchema($schemafile, $packagename, '', $prefix, true)) { + $modx->log(modX::LOG_LEVEL_ERROR, 'Could not generate XML schema', '', 'FormIt2db Hook'); + } + } + $generator->parseSchema($schemafile, $modelpath); + $modx->log(modX::LOG_LEVEL_WARN, 'autoPackage parameter active', '', 'FormIt2db Hook'); + $modx->addPackage($packagename, $modelpath, $prefix); $classname = $generator->getClassName($tablename); +} else { + $modx->addPackage($packagename, $modelpath, $prefix); } if ($fieldname) { @@ -66,8 +88,8 @@ if (!is_object($dataobject) || !($dataobject instanceof xPDOObject)) { $errorMsg = 'Failed to create object of type: ' . $classname; $hook->addError('error_message', $errorMsg); - $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'formit2db Hook'); - return FALSE; + $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'FormIt2db Hook'); + return false; } $formFields = $hook->getValues(); @@ -91,8 +113,8 @@ if (!$dataobject->save()) { $errorMsg = 'Failed to save object of type: ' . $classname; $hook->addError('error_message', $errorMsg); - $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'formit2db Hook'); - return FALSE; + $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'FormIt2db Hook'); + return false; } -return TRUE; +return true; ?> \ No newline at end of file