Skip to content

Commit

Permalink
Update to 1.1.2
Browse files Browse the repository at this point in the history
autoPackage parameter: Package generation is executed in FormIt2db too. Before it was only active in db2FormIt.
  • Loading branch information
Jako committed Dec 12, 2014
1 parent f7dc535 commit a0dad49
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion _build/data/properties/properties.db2formit.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
'desc' => 'prop_formit2db.autoPackage',
'type' => 'combo-boolean',
'options' => '',
'value' => FALSE,
'value' => false,
'lexicon' => 'formit2db:properties',
)
);
Expand Down
2 changes: 1 addition & 1 deletion _build/data/properties/properties.formit2db.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
'desc' => 'prop_formit2db.autoPackage',
'type' => 'combo-boolean',
'options' => '',
'value' => FALSE,
'value' => false,
'lexicon' => 'formit2db:properties',
)
);
Expand Down
2 changes: 2 additions & 0 deletions core/components/formit2db/docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
38 changes: 19 additions & 19 deletions core/components/formit2db/elements/snippets/snippet.db2formit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand All @@ -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 {
Expand All @@ -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));
Expand All @@ -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' :
Expand All @@ -115,5 +115,5 @@
}
}

return TRUE;
return true;
?>
56 changes: 39 additions & 17 deletions core/components/formit2db/elements/snippets/snippet.formit2db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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;
?>

0 comments on commit a0dad49

Please sign in to comment.