<![CDATA[ NEW: Create Classes, Maps & Tables From Dashboard Widget! - My Forums]]> https://forums.modx.com/thread/?thread=104447 <![CDATA[NEW: Create Classes, Maps & Tables From Dashboard Widget!]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget?page=2#dis-post-561801
Warning:
I am getting the following errors I have no idea how to debug ATM.

Errors:
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 666) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1264) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1289) Could not get table name for class: UserCommentFlags
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1840) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1336) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1341) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1438) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1361) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1573) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1584) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 618) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 621) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 661) PHP warning: Illegal offset type in isset or empty
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1594) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/xpdo.class.php : 1603) PHP warning: Illegal offset type
[2018-09-28 17:29:34] (ERROR @ core_dev/xpdo/om/mysql/xpdomanager.class.php : 256) Could not create table 
SQL: CREATE TABLE  () ENGINE=InnoDB
ERROR: Array
(
    [0] => 42000
    [1] => 1064
    [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '() ENGINE=InnoDB' at line 1
)

[2018-09-28 17:29:34] (ERROR in schemaToDatabase @ /var/www/cannacle/Oxg9v_core_dev/cache/includes/elements/modsnippet/224.include.cache.php : 44) Error: Could not generate Table/s!


The schema file...
<?xml version="1.0" encoding="UTF-8"?>
<model package="Social" baseClass="xPDOObject" platform="mysql" defaultEngine="InnoDB" version="1.1">
	<object class="UserCommentFlags" table="user_comment_flags" extends="xPDOSimpleObject">
		<field key="item_id" dbtype="bigint" precision="20" phptype="integer" null="false" />
		<field key="user_id" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="reason" dbtype="int" precision="1" phptype="integer" null="false" />
		<field key="created" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
		<field key="reviewed" dbtype="timestamp" phptype="timestamp" null="true" />
	</object>
	<object class="UserCommentLikes" table="user_comment_likes" extends="xPDOSimpleObject">
		<field key="item_id" dbtype="bigint" precision="20" phptype="integer" null="false" index="unique" />
		<field key="liked_by" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="liked_on" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />

		<index alias="id" name="id" primary="false" unique="true" type="BTREE" >
			<column key="item_id" length="" collation="A" null="false" />
		</index>
	</object>
	<object class="UserFollowers" table="user_followers" extends="xPDOObject">
		<field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" />
		<field key="list" dbtype="longtext" phptype="string" null="false" />

		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
			<column key="id" length="" collation="A" null="false" />
		</index>
	</object>
	<object class="UserGroupAdmins" table="user_group_admins" extends="xPDOSimpleObject">
		<field key="user_id" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="group_id" dbtype="int" precision="12" phptype="integer" null="false" />
		<field key="moderate" dbtype="int" precision="1" phptype="integer" null="false" default="1" />
		<field key="kick" dbtype="int" precision="1" phptype="integer" null="false" default="1" />
		<field key="ban" dbtype="int" precision="1" phptype="integer" null="false" default="1" />
		<field key="added" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />

		<index alias="id" name="id" primary="false" unique="true" type="BTREE" >
			<column key="id" length="" collation="A" null="false" />
		</index>
	</object>
	<object class="UserGroups" table="user_groups" extends="xPDOSimpleObject">
		<field key="owner_id" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="name" dbtype="varchar" precision="32" phptype="string" null="false" />
		<field key="descrption" dbtype="int" precision="140" phptype="integer" null="false" />
		<field key="created" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
		<field key="privacy" dbtype="int" precision="2" phptype="integer" null="false" default="0" />

		<index alias="id" name="id" primary="false" unique="true" type="BTREE" >
			<column key="id" length="" collation="A" null="false" />
		</index>
	</object>
	<object class="UserPostFlags" table="user_post_flags" extends="xPDOSimpleObject">
		<field key="item_id" dbtype="bigint" precision="20" phptype="integer" null="false" />
		<field key="user_id" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="reason" dbtype="int" precision="1" phptype="integer" null="false" />
		<field key="created" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
		<field key="reviewed" dbtype="timestamp" phptype="timestamp" null="true" />
	</object>
	<object class="UserPostLikes" table="user_post_likes" extends="xPDOSimpleObject">
		<field key="item_id" dbtype="bigint" precision="20" phptype="integer" null="false" />
		<field key="liked_by" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="liked_on" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
	</object>
	<object class="UserPostShares" table="user_post_shares" extends="xPDOSimpleObject">
		<field key="item_id" dbtype="bigint" precision="20" phptype="integer" null="false" />
		<field key="shared_by" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="shared_on" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
	</object>
	<object class="UserPosts" table="user_posts" extends="xPDOSimpleObject">
		<field key="owner_id" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="wall" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="type" dbtype="varchar" precision="32" phptype="string" null="false" default="wall" />
		<field key="created" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
		<field key="deleted" dbtype="timestamp" phptype="timestamp" null="true" />
		<field key="content" dbtype="text" phptype="string" null="false" />
		<field key="privacy" dbtype="int" precision="2" phptype="integer" null="false" default="0" />
		<field key="flagged" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
		<field key="liked" dbtype="bigint" precision="20" phptype="integer" null="false" default="0" />

		<index alias="id" name="id" primary="false" unique="true" type="BTREE" >
			<column key="id" length="" collation="A" null="false" />
		</index>
	</object>
	<object class="UserProfileFlags" table="user_profile_flags" extends="xPDOSimpleObject">
		<field key="item_id" dbtype="bigint" precision="20" phptype="integer" null="false" />
		<field key="user_id" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="reason" dbtype="int" precision="1" phptype="integer" null="false" />
		<field key="created" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
		<field key="reviewed" dbtype="timestamp" phptype="timestamp" null="true" />
	</object>
	<object class="UserProfileLikes" table="user_profile_likes" extends="xPDOObject">
		<field key="id" dbtype="bigint" precision="20" phptype="integer" null="false" index="pk" />
		<field key="item_id" dbtype="bigint" precision="20" phptype="integer" null="false" />
		<field key="liked_by" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="liked_on" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />

		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
			<column key="id" length="" collation="A" null="false" />
		</index>
	</object>
	<object class="UserReplyFlags" table="user_reply_flags" extends="xPDOSimpleObject">
		<field key="item_id" dbtype="bigint" precision="20" phptype="integer" null="false" />
		<field key="user_id" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="reason" dbtype="int" precision="1" phptype="integer" null="false" />
		<field key="created" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
		<field key="reviewed" dbtype="timestamp" phptype="timestamp" null="true" />
	</object>
	<object class="UserReplyLikes" table="user_reply_likes" extends="xPDOSimpleObject">
		<field key="item_id" dbtype="bigint" precision="20" phptype="integer" null="false" index="unique" />
		<field key="liked_by" dbtype="int" precision="11" phptype="integer" null="false" />
		<field key="liked_on" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />

		<index alias="id" name="id" primary="false" unique="true" type="BTREE" >
			<column key="item_id" length="" collation="A" null="false" />
		</index>
	</object>
	<object class="UserStreams" table="user_streams" extends="xPDOObject">
		<field key="owner_id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" />
		<field key="following" dbtype="longtext" phptype="string" null="true" />

		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
			<column key="owner_id" length="" collation="A" null="false" />
		</index>
		<index alias="owner_id" name="owner_id" primary="false" unique="true" type="BTREE" >
			<column key="owner_id" length="" collation="A" null="false" />
		</index>
	</object>
	<object class="UserWalls" table="user_walls" extends="xPDOObject">
		<field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" />
		<field key="username" dbtype="varchar" precision="64" phptype="string" null="false" />
		<field key="privacy" dbtype="int" precision="2" phptype="integer" null="false" default="0" />
		<field key="whitelist" dbtype="longtext" phptype="string" null="true" />
		<field key="blacklist" dbtype="mediumtext" phptype="string" null="true" />

		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
			<column key="id" length="" collation="A" null="false" />
		</index>
	</object>
</model>


The map file for the UserCommentFlags table...
<?php
$xpdo_meta_map['UserCommentFlags']= array (
  'package' => 'Social',
  'version' => '1.1',
  'table' => 'user_comment_flags',
  'extends' => 'xPDOSimpleObject',
  'tableMeta' => 
  array (
    'engine' => 'InnoDB',
  ),
  'fields' => 
  array (
    'item_id' => NULL,
    'user_id' => NULL,
    'reason' => NULL,
    'created' => 'CURRENT_TIMESTAMP',
    'reviewed' => NULL,
  ),
  'fieldMeta' => 
  array (
    'item_id' => 
    array (
      'dbtype' => 'bigint',
      'precision' => '20',
      'phptype' => 'integer',
      'null' => false,
    ),
    'user_id' => 
    array (
      'dbtype' => 'int',
      'precision' => '11',
      'phptype' => 'integer',
      'null' => false,
    ),
    'reason' => 
    array (
      'dbtype' => 'int',
      'precision' => '1',
      'phptype' => 'integer',
      'null' => false,
    ),
    'created' => 
    array (
      'dbtype' => 'timestamp',
      'phptype' => 'timestamp',
      'null' => false,
      'default' => 'CURRENT_TIMESTAMP',
    ),
    'reviewed' => 
    array (
      'dbtype' => 'timestamp',
      'phptype' => 'timestamp',
      'null' => true,
    ),
  ),
);


Caveats:
Requires FormIt
The error thing mentioned above when tested on 2.6.x-dev merged with...
sdrenth:automate-static-elements running on...
PHP Version 7.0.30-0ubuntu0.16.04.1
mySQL Version 5.7.23-0ubuntu0.16.04.1

Here's the Widget's Chunk...

Name: SchemaToDB
[[FormIt?&hooks=`schemaParser,schemaToDatabase`]]
<p style="padding-bottom:10px;">[[+std.response]]</p>
<form name="stdForm" action="" method="post" class="form">
    <label>Prefix <input type="text" name="stdPrefix" id="stdPrefix" value="[[+std.prefix]]"/></label>
    <label>Package <input type="text" name="stdPackage" id="stdPackage" value="[[+std.package]]"/></label>
    <input type="submit" name="makeItHappen" value="STD It!"/>
</form>


Here are the snippets...

Name: schemaParser
<?php
// Get the perameters passed by FormIt 
$parameters = $hook->getValues();
// Set variables for the passed perameters
$packagename = $parameters['stdPackage'];
// Set the modelpath for addPackage to use later
$modelpath = MODX_CORE_PATH.'components/'.$packagename.'/model/';
// Set the filename of the schema from the package name
$filepath = $modelpath.'schema/'.$packagename.'.mysql.schema.xml';
// Get the manager
$manager = $modx->getManager();
// Get the generator
$generator = $manager->getGenerator();
// Generate or update the class and map files
$result = $generator->parseSchema($filepath,$modelpath);
return $result;


Name: schemaToDatabase
<?php
/* -----------------------------------------------------------------
 * Extension: STD (Schema to Database)
 * -----------------------------------------------------------------
 * Version: 1.0.0
 * Since: September. 26, 2018
 * Author: Aaron Kent <[email protected]>
 * License: GNU GPLv2 (or later)
 *
 * This will create database table/s for a Single Package
 * based on a schema file.
 *
 * schemaToDatabase
 *
 * @package schemaToDatabase
 * @subpackage schemaToDatabase snippet
 */
// Get the perameters passed by FormIt 
$parameters = $hook->getValues();
// Set variables for the passed perameters
$prefix = $parameters['stdPrefix'];
$packagename = $parameters['stdPackage'];
// Set the modelpath for addPackage to use later
$modelpath = MODX_CORE_PATH.'components/'.$packagename.'/model/';
// Set the filename of the schema from the package name
$filename = $packagename.'.mysql.schema.xml';
// Set the package path for the XML file to object conversion
$packagePath = $modelpath.'schema/'.$filename;
// Set the object
$xmlObj = simplexml_load_string(file_get_contents($packagePath));
// Get the manager
$manager = $modx->getManager();
// Add the package for manager to use
$modx->addPackage($packagename,$modelpath,$prefix);
// Empty the output vriable
$op = '';
    // Iterate through the object created from the schema file
    foreach ($xmlObj->object as $object) {
        // Catch errors that occur with 'if !' check
        if (!$manager->createObjectContainer($object['class'])) {
            // Error control start
            $response = 'Error: Could not generate Table/s!';
            $modx->log(modX::LOG_LEVEL_ERROR, $response, '',
                'schemaToDatabase');
            $modx->setPlaceholders( array(
                'response' => $response,
                'prefix' => $prefix,
                'package' => $packagename,
            ), 'std.' );
            // End error control, and return
            return false;
        } else {
            // Concat the output for display and logging
            $op .= 'created '.$object['table'].' - ';
        }
    }
// Log passing result - for development only, remove in production
$modx->log( modX::LOG_LEVEL_WARN, 'schemaToDatabase '.$op.
    ' tables for package: '.$packagename, '', 'schemaToDatabase' );
// Set passing response
$response = 'STD '.$op.'the table/s for packagename: '.$packagename;
// Set passing placeholders
$modx->setPlaceholders( array(
   'response' => $response.' Package:'.$package,
   'prefix' => $prefix,
   'package' => $packagename,
), 'std.' );
// Return
return true;


The schemaParser is working, but there seems to be a core bug I'm not catching?

You all have no idea how much your ongoing help has meant to mo over these past 4 years. Thank you very much!

Please help me get this fixed so I can move on to final testing and release of the social networking platform.]]>
aaronkent Sep 28, 2018, 05:43 PM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget?page=2#dis-post-561801
<![CDATA[Re: NEW: Create Classes, Maps & Tables From Dashboard Widget!]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561883 ]]> BobRay Oct 02, 2018, 08:26 PM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561883 <![CDATA[Re: NEW: Create Classes, Maps & Tables From Dashboard Widget!]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561864 aaronkent Oct 02, 2018, 12:07 AM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561864 <![CDATA[Re: NEW: Create Classes, Maps & Tables From Dashboard Widget!]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561863
FWIW, I would not attempt to use FormIt in a Widget. FormIt introduces a lot of complexity and widgets are complex enough to begin with. The reason I suggested the test is that FormIt's getValue() may not work in a widget. FormIt may be returning an error message that contains an error message that MODX is trying to parse as if it's the return from the form.

I'd either roll my own form, or create a processor and call it with JavaScript (probably the latter).]]>
BobRay Oct 01, 2018, 10:38 PM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561863
<![CDATA[Re: NEW: Create Classes, Maps & Tables From Dashboard Widget!]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561859
*Edited*:
I tried to set breakpoints in the xpdo core class to see where it's missing data, but that causes the whole manager to simply crash *instantly at load*.

Added these two lines starting at line #618 in the xpdo.class.php file...
$er = print_r($this->map);
$this->log(xPDO::LOG_LEVEL_ERROR, $er);

Results in imediate output to screen of the $er variable *before the widget is used, or FotmIt is actioned*.

Wow. I expect that code should only output to the manager log, not directly to the screen. This is happening in 2.6.x-dev with error reporting E_ALL set. Maybe that's why.

I'll worry about it when I get the last working install recovered from this other hard drive. I'm just starting to get more upset the more I attempt to fudge things. Better to return to last know working state, then address the packaging of the social plugin. This dashboard widget can wait till never for all I care at this point.

*I'm using another widget with FormIt in the dashboard for a very long time without issues. It still works properly.*]]>
aaronkent Oct 01, 2018, 08:17 PM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561859
<![CDATA[Re: NEW: Create Classes, Maps & Tables From Dashboard Widget! (Best Answer)]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561844
FYI - Probably not your problem, but UserGroups is already an aggregate alias in MODX.

Here's something else to try, since you can't run it in a debugger:

$parameters = $hook->getValues();
$modx->log(modX::LOG_LEVEL_ERROR, "PARAMETERS: " . print_r($parameters, true)); 


In case what you're getting from FormIt is not what you think.

When I have to do a complex project (e.g., MyComponent), I create the snippets and plugins as .php files that will instantiate MODX if it's not already there so I can run them in my code editor. That way I can run them in the debugger in PhpStorm and set breakpoints and step through them to make sure everything is as it should be. I can use MyComponent to import them into MODX once I know they work.

I try to create unit tests for each one and for any classes they use. It's a lot of work, but it's a comfort to be able to run the unit tests after I've made changes to make sure everything still works and it saves me time in the long run. MyComponent's LexiconHelper also makes creating the language files a piece of cake and it will create the package's transport file for me automatically.

]]>
BobRay Oct 01, 2018, 04:46 AM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561844
<![CDATA[Re: NEW: Create Classes, Maps & Tables From Dashboard Widget!]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561843
Then, the same exact code running in 2.5.7-pl produces different errors in xpdogenerator.class.php - My guess is compatability of the schema?

I mean, I've debugged my code to core, and that's where it's erroring, in the core classes.

I checked the class var that I'm passing, it's there, but createObjectContainer() seems unable to get the table name fron the map file or the schema that parseSchema() creates. parseSchema() passes on both versions.

I'll install PHPStorm if it runs on Ubuntu, that's what OS I'll be using on the desktop that's being delivered next week. Currently on iPad Pro til then. Also using CodeAnywhere for now on iOS/browser.]]>
aaronkent Oct 01, 2018, 12:43 AM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561843
<![CDATA[Re: NEW: Create Classes, Maps & Tables From Dashboard Widget!]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561841 https://stackoverflow.com/questions/2732451/php-how-do-i-fix-this-illegal-offset-type-error.

I've run into this problem with empty():

if (empty(someFunction())) {

}


The fix, in case you find something like that in your code:

$x = someFunction();
if (empty($x)) {

}


PhpStorm, btw, lets you set what version of PHP you're using and warns about all kinds of stuff like that. It saves me many hours of debugging.
]]>
BobRay Sep 30, 2018, 08:23 PM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561841
<![CDATA[Re: NEW: Create Classes, Maps & Tables From Dashboard Widget!]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561826 The error has changed for the same code as it is above, in my OP.

[2018-09-29 16:43:12] (ERROR @ /home/m1chaelkent/public_html/rhythm.auction/core/xpdo/om/xpdogenerator.class.php : 203) PHP warning: SimpleXMLElement::__construct(): core/components/Social/model/schema/Social.mysql.schema.xml:40: parser error : Premature end of data in tag object line 39


#39: <object class="UserGroups" table="user_groups" extends="xPDOSimpleObject">

[2018-09-29 16:43:12] (ERROR @ core/xpdo/om/xpdogenerator.class.php : 203) PHP warning: SimpleXMLElement::__construct(): eld key="owner_id" dbtype="int" precision="11" phptype="integer" null="false" />

[2018-09-29 16:43:12] (ERROR @ core/xpdo/om/xpdogenerator.class.php : 203) PHP warning: SimpleXMLElement::__construct():                                                                                ^
[2018-09-29 16:43:12] (ERROR @ core/xpdo/om/xpdogenerator.class.php : 203) PHP warning: SimpleXMLElement::__construct(): core/components/Social/model/schema/Social.mysql.schema.xml:40: parser error : Premature end of data in tag model line 2


#2: <model package="Social" baseClass="xPDOObject" platform="mysql" defaultEngine="InnoDB" version="1.1">

[2018-09-29 16:43:12] (ERROR @ core/xpdo/om/xpdogenerator.class.php : 203) PHP warning: SimpleXMLElement::__construct(): eld key="owner_id" dbtype="int" precision="11" phptype="integer" null="false" />

[2018-09-29 16:43:12] (ERROR @ core/xpdo/om/xpdogenerator.class.php : 203) PHP warning: SimpleXMLElement::__construct():


Why is it cutting off the line at `eld...` when it is `<field...`? That's strange.
As far as I can tell from reading the docs, the xml file looks correct. Am I wrong?

Every single plugin, and that code you linked me to, deals only with creating SCHEMA and maps from existing tables...However, I am trying to create the TABLES from existing schema files.

The map files no longer create any errors when using addPackage() after running parseSchema() and overwriting them.

Now I'm on to running createObjectContainer() which is where the errors are happening, while parsing the schemas generated by your code, in 2016, when I backed this up. I've now ran the parseSchema() on those schemas so I can rebuild the database tables, because of a data loss.

This has got to be the most frustraiting part of the plugin/extra building process. For a tiny plugin, no sweat, but for an entire social network platform it's worse than pulling teeth. Lol.

Thank goodness I've got another actual database backup in another hard drive I can access next week. Just very crapy dealing with all the delays for packaging and redeployment, and I'd still like to get to the bottom of why createObjectContainer() is crashing with `illegal offset for isset and empty` errors in 2.6.x-dev.]]>
aaronkent Sep 29, 2018, 04:57 PM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561826
<![CDATA[Re: NEW: Create Classes, Maps & Tables From Dashboard Widget!]]> https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561815 Quote from: BobRay at Sep 28, 2018, 08:07 PM
It might help to look at the code at the end of this article.

As you've found, it's very difficult to debug stuff like this.

One method is to create a local install of MODX, move your code to a file where you instantiate MODX first, then step through the code in a debugger that's part of a good code editor like PhpStorm.

Another approach I usually use is to create the DB tables manually, use the script in the first link above to create the schema files, then modify them to include the object relationships and run the code again with $createSchema=false to create the class and map files.

Another thought: PHP 7.0 has some known problems, so upgrading it couldn't hurt.

Yes, @BobRay, it is!

I'll update PHP, but I don't have access to a local server yet. Soon though.

If the PHP update doesn't work, I'll just wait till my linux box gets here. Then I can recover the last working install that's sitting next to me on a hard drive. Currently working from an iPad Pro. It get's frustraiting sometimes, but I still have some descent tools.

Thank you for the help, and the link @BobRay!]]>
aaronkent Sep 28, 2018, 10:25 PM https://forums.modx.com/thread/104447/new-create-classes-maps-tables-from-dashboard-widget#dis-post-561815