Skip to content

Commit b5640a6

Browse files
authored
Merge pull request #12 from jaredfhealy/3.x.bc
3.x.bc
2 parents c74e0f1 + 0dba60c commit b5640a6

File tree

74 files changed

+2407
-1068
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2407
-1068
lines changed

_build/build.schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
//{base_path}/core/components/
2828
$projectRootDir = MODX_BASE_PATH . 'core/components/';
2929

30-
//{base_path}/core/components/ExtraBuilder
31-
$corePath = $projectRootDir . 'ExtraBuilder/';
30+
//{base_path}/core/components/extrabuilder
31+
$corePath = $projectRootDir . 'extrabuilder/';
3232

33-
//{base_path}/core/components/ExtraBuilder/schema/extrabuilder.mysql.schema.xml
33+
//{base_path}/core/components/extrabuilder/schema/extrabuilder.mysql.schema.xml
3434
$schemaFile = $corePath . "schema/extrabuilder.mysql.schema.xml";
3535

3636
/**

_build/resolvers/tables.php

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,68 @@
88
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
99
case xPDOTransport::ACTION_INSTALL:
1010
case xPDOTransport::ACTION_UPGRADE:
11-
$corePath = MODX_CORE_PATH . 'components/{package_key}/';
12-
$eb; /* Service class */
11+
// Initial variables
12+
$packageKey = '{package_key}';
13+
$keyLower = strtolower($packageKey);
14+
$corePath = MODX_CORE_PATH . "components/$keyLower/";
1315
$isV3 = $modx->getVersionData()['version'] >= 3;
16+
17+
// Include model based on version
1418
if (!$isV3) {
15-
$modx->log(xPDO::LOG_LEVEL_ERROR, "This version of ExtraBuilder is compatible with MODX 3.0 and higher only.");
19+
// Main class path
20+
$classFilePath = $corePath . "src/{$packageKey}.php";
21+
if (is_file($classFilePath)) {
22+
// Get the contents
23+
$contents = file_get_contents($classFilePath);
24+
25+
// For our main class file, remove namespace block
26+
$key = '//v3 only';
27+
$start = strpos($contents, $key);
28+
if ($start !== false) {
29+
$end = strpos($contents, $key, $start + strlen($key));
30+
$contents = substr_replace($contents, '', $start, $end - $start + strlen($key));
31+
}
32+
33+
// Write the file back
34+
file_put_contents($classFilePath, $contents);
35+
36+
// Now try including and loading the file
37+
@include_once $classFilePath;
38+
$myService = new $packageKey($modx, ["install" => true]);
39+
if ($myService) {
40+
// Rename classes and remove namespaces in processors
41+
$myService->replaceOnV2Install($corePath."src/Processors/");
42+
43+
// Also replace classes on index class file
44+
$myService->replaceClassesForV2($corePath.'index.class.php');
45+
46+
// Attempt to add the package
47+
$result = $modx->addPackage("$keyLower.v2.model", MODX_CORE_PATH.'components/');
48+
if (!$result) {
49+
$modx->log(xPDO::LOG_LEVEL_ERROR, "Unable to add package. Install failed.");
50+
exit();
51+
}
52+
}
53+
}
54+
else {
55+
// This package has no class file, just add the package
56+
$result = $modx->addPackage("$keyLower.v2.model", MODX_CORE_PATH.'components/');
57+
if (!$result) {
58+
$modx->log(xPDO::LOG_LEVEL_ERROR, "Unable to add package. Install failed.");
59+
exit();
60+
}
61+
}
1662
}
1763
else {
1864
// Check for the bootstrap file and include it
1965
if (file_exists($corePath.'bootstrap.php')) {
2066
// For v3, the bootstrap file needs a namespace object, which doesn't exist yet
2167
// Create an object so it can reference it
22-
$namespace = $object->toArray();
23-
$namespace['path'] = $corePath;
24-
$namespace['assets_path'] = MODX_ASSETS_PATH . 'components/{package_key}/';
68+
$namespace = [
69+
'name' => $keyLower,
70+
'path' => $corePath,
71+
'assets_path' => MODX_ASSETS_PATH . "components/$keyLower/"
72+
];
2573
require $corePath.'bootstrap.php';
2674
}
2775
else {
@@ -32,19 +80,29 @@
3280
$manager = $modx->getManager();
3381
$objects = [];
3482
$classPrefix = "";
35-
$namespace = "{package_key}";
36-
$nsLower = strtolower($namespace);
37-
$schemaFile = MODX_CORE_PATH . "components/{package_key}/schema/{$nsLower}.mysql.schema.xml";
38-
if (is_file($schemaFile)) {
83+
$schemaFile = MODX_CORE_PATH . "components/{$keyLower}/schema/{$keyLower}.mysql.schema.xml";
84+
if (!is_file($schemaFile)) {
85+
$schemaFile = MODX_CORE_PATH . "components/{$keyLower}/v2/schema/{$keyLower}.mysql.schema.xml";
86+
if (!is_file($schemaFile)) {
87+
$schemaFile = MODX_CORE_PATH . "components/{$keyLower}/model/schema/{$keyLower}.mysql.schema.xml";
88+
if (!is_file($schemaFile)) {
89+
$modx->log(xPDO::LOG_LEVEL_ERROR, "Unable to load schema file...");
90+
exit();
91+
}
92+
}
93+
}
94+
95+
// If we have a schema file
96+
if (is_file($schemaFile)) {
3997
$schema = new SimpleXMLElement($schemaFile, 0, true);
4098
if (isset($schema->object)) {
4199
foreach ($schema->object as $obj) {
42100
$objects[] = (string) $obj['class'];
43101
}
44102
}
45103

46-
// Store the classPrefix
47-
$classPrefix = $schema[0]['package'];
104+
// Store the package value
105+
$classPrefix = trim($schema[0]['package'], '\\').'\\';
48106
unset($schema);
49107
}
50108

_build/resolvers/uninstall/remove_tables.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,31 @@
77

88
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
99
case xPDOTransport::ACTION_UNINSTALL:
10-
// Store the core path
11-
$corePath = MODX_CORE_PATH . 'components/{package_key}/';
10+
// Store the core path and version
11+
$packageKey = '{package_key}';
12+
$keyLower = strtolower($packageKey);
13+
$corePath = MODX_CORE_PATH . "components/{$keyLower}/";
14+
$isV3 = $modx->getVersionData()['version'] >= 3;
1215

13-
// Check for the bootstrap file and include it
14-
if (file_exists($corePath.'bootstrap.php')) {
15-
require $corePath.'bootstrap.php';
16+
// If this is 2.x
17+
if (!$isV3) {
18+
$modx->addPackage("$keyLower.v2.model", MODX_CORE_PATH.'components/');
19+
}
20+
else {
21+
$modx->addPackage("$packageKey\Model", $namespace['path'] . 'src/', null, "{$packageKey}\\");
1622
}
1723

1824
// Get the manager
1925
$manager = $modx->getManager();
2026

2127
// Classes array is dynamically replaced on Transport build
22-
$classes = $classesPlaceholder;
28+
$classes3 = $classesPlaceholder3;
29+
$classes2 = $classesPlaceholder2;
30+
$classes = $isV3 ? $classes3 : $classes2;
2331

2432
// Only proceed if the json has been replaced
2533
foreach ($classes as $index => $class) {
34+
// Remove the class/table
2635
$manager->removeObjectContainer($class);
2736
}
2837

_build/templates/bootstrap.tpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use xPDO\xPDO;
1010

1111
// Add the service
1212
try {
13-
// Load the classes
14-
$loader = $modx::getLoader();
15-
$loader->addPsr4('{$namespace}\\', $namespace['path'].'src/');
13+
// Add the package and model classes
14+
$modx->addPackage('{$namespace}\Model', $namespace['path'] . 'src/', null, '{$namespace}\\');
1615
1716
if (class_exists('{$namespace}\\{$namespace}')) {
1817
$modx->services->add('{$namespace}', function($c) use ($modx) {

assets/connector.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
*/
1313

1414
// Define package name and rootDir
15-
$packageKey = basename(dirname(__FILE__, 2)) === 'components' ? basename(dirname(__FILE__)) : basename(dirname(__FILE__, 2));
15+
$packageKey = 'ExtraBuilder';
16+
$keyLower = strtolower($packageKey);
1617

1718
// Determine where we're at. Asset path possibilities
1819
// Development: core/components/<key>/assets
@@ -32,18 +33,29 @@
3233

3334
// Bring in the connector index
3435
require_once(MODX_CONNECTORS_PATH . 'index.php');
35-
3636
}
3737

3838
// If we now have a core path defined
3939
if (defined('MODX_CORE_PATH')) {
40+
// Check the version
41+
$version = $modx->getVersionData()['version'];
42+
$isV3 = $version >= 3;
43+
4044
// Dynamic classname based on packageKey
41-
$service = $modx->services->has($packageKey) ? $modx->services->get($packageKey) : "";
45+
if (!$isV3) {
46+
// Include our main class
47+
@include_once MODX_CORE_PATH . "components/{$keyLower}/src/{$packageKey}.php";
48+
$service = new $packageKey($modx);
49+
}
50+
else {
51+
$service = $modx->services->has($packageKey) ? $modx->services->get($packageKey) : "";
52+
}
53+
54+
// Add the service to MODX
4255
if ($service) {
43-
$serviceKey = $service->config['serviceKey'];
56+
$serviceKey = $service->config['serviceKey'] ?: $packageKey;
4457
$modx->$serviceKey =& $service;
4558
}
46-
$modx->lexicon->load("${packageKey}:default");
4759

4860
if (!$modx->$serviceKey) {
4961
header("Content-Type: application/json; charset=UTF-8");
@@ -56,8 +68,11 @@
5668
die();
5769
}
5870

71+
// Load the default lexicon
72+
$modx->lexicon->load($modx->eb->config['lexiconKey'].":default");
73+
5974
/* handle request */
60-
$path = $modx->getOption('processorsPath', $modx->$serviceKey->config, $corePath . 'processors/');
75+
$path = $modx->getOption('processorsPath'.$version, $modx->$serviceKey->config, $corePath . 'processors/');
6176
$modx->request->handleRequest(['processors_path' => $path]);
6277
}
6378
else {

bootstrap.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010

1111
// Add the service
1212
try {
13-
// Load the classes
14-
$loader = $modx::getLoader();
15-
$loader->addPsr4('ExtraBuilder\\', $namespace['path'].'src/');
13+
// Add the package and model classes
14+
$modx->addPackage('ExtraBuilder\Model', $namespace['path'] . 'src/', null, 'ExtraBuilder\\');
1615

1716
if (class_exists('ExtraBuilder\\ExtraBuilder')) {
1817
$modx->services->add('ExtraBuilder', function($c) use ($modx) {
19-
return new Extrabuilder($modx);
18+
return new ExtraBuilder($modx);
2019
});
2120
}
2221
else {
23-
$modx->log(xPDO::LOG_LEVEL_ERROR, "Class ExtraBuilder\\ExtraBuilder does not exist.");
22+
$modx->log(xPDO::LOG_LEVEL_ERROR, "Class ExtraBuilder\\ExtraBuilder does not exist.".print_r($loader->getPrefixesPsr4(), true));
2423
}
2524
}
2625
catch (\Exception $e) {

docs/changelog.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
ExtraBuilder 2.0.0 alpha
1+
ExtraBuilder 2.0.0 rc2
2+
========================
3+
- Corrected directory capitalization to follow standard
4+
- Unified codebase for MODX 2/3 so both have the same ExtJS UI
5+
- Refactored and improved importing of existing schemas
6+
- Enhanced Index specification capabilities
7+
- Added MODX version dependent descriptions and logic where needed
8+
- Use MODX 3 to build packages for both MODX 2 & 3
9+
10+
ExtraBuilder 2.0.0 rc1
211
========================
312
- Complete rebuild for MODX 3
413
- Complete UI rebuild using ExtJS instead of Vue

docs/readme.txt

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
Full Documentation: https://gearvy.com/extrabuilder
1+
Full Documentation
2+
===================
3+
For more exhaustive documentation, refer to Github and Gearvy.com.
4+
- https://github.com/jaredfhealy/extrabuilder
5+
- https://gearvy.com/docs/extrabuilder/
26

3-
Manage Packages and Tables
4-
--------------------------
5-
This Extra allows you to build custom tables, and packages. You can then create a transport package to move that functionality between MODX instance, or publish to the MODX Extras directory for the community to utilize.
7+
Create Custom Tables, Manage Packages and Transport
8+
==========================
9+
This Extra allows you to build custom tables, fields, and package it all up. You can then create a transport package to move that functionality between MODX instance, or publish to the MODX Extras directory for the community to utilize.
610

7-
Features Include
8-
--------------------------
9-
1. Package Builder
10-
a. Create custom packages including the model, objects (custom tables), fields and relationships
11-
b. Preview schema xml
12-
c. Build and create missing tables or add columns
13-
2. Transport Builder
14-
a. Create a transport package and specify the version details
15-
b. Generate the transport zip and directories
16-
c. Automatically includes file preservers based on the Category
17-
d. Automatically includes elements for that Category
11+
Use this in non-production instances to develop new MODX Extras, or custom data tables for clients.
12+
13+
Package Builder (Custom tables)
14+
=============================
15+
- Create custom packages including the model, objects (custom tables), fields and relationships
16+
- Preview schema xml
17+
- Build and create missing tables or add columns
18+
19+
Transport Builder
20+
=================
21+
- Create a transport package and specify the version details
22+
- Generate the transport zip and directories
23+
- Automatically includes file preservers based on the Category
24+
- Automatically includes elements for that Category

index.class.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
//v3 only
34
use MODX\Revolution\modExtraManagerController;
45
use xPDO\xPDO;
6+
//v3 only
57

68
/**
79
* Base controller for showing ExtraBuilder
810
*
911
*/
10-
class ExtraBuilderIndexManagerController extends modExtraManagerController
12+
class ExtrabuilderIndexManagerController extends modExtraManagerController
1113
{
1214

1315
/** @var ExtraBuilder\ExtraBuilder $eb */
@@ -28,10 +30,33 @@ class ExtraBuilderIndexManagerController extends modExtraManagerController
2830
*/
2931
public function initialize()
3032
{
31-
// Get our service class
32-
$this->eb = $this->modx->services->has('ExtraBuilder') ? $this->modx->services->get('ExtraBuilder') : "";
33-
if (!$this->eb) {
34-
return $this->failure("Unable to load ExtraBuilder Service Class.");
33+
// Check the version
34+
$isV3 = $this->modx->getVersionData()['version'] >= 3;
35+
36+
// Define package name and rootDir
37+
$packageKey = 'ExtraBuilder';
38+
$keyLower = strtolower($packageKey);
39+
40+
// Dynamic classname based on packageKey
41+
if (!$isV3) {
42+
// Include our main class
43+
@include_once MODX_CORE_PATH . "components/{$keyLower}/src/{$packageKey}.php";
44+
$service = new $packageKey($this->modx);
45+
}
46+
else {
47+
$service = $this->modx->services->has($packageKey) ? $this->modx->services->get($packageKey) : "";
48+
}
49+
50+
// Add the service to MODX
51+
if ($service) {
52+
$serviceKey = $service->config['serviceKey'] ?: $packageKey;
53+
$this->$serviceKey =& $service;
54+
$this->modx->$serviceKey =& $service;
55+
}
56+
57+
// Return an error if we don't have our service class
58+
if (!$this->$serviceKey) {
59+
return $this->failure("Unable to load Service Class for: $packageKey");
3560
}
3661

3762
// Return true or parent::initialize() which also just returns true
@@ -62,7 +87,11 @@ public function process(array $scriptProperties = [])
6287
"jsPrefix" => "EB",
6388
"config" => $this->eb->config,
6489
"model" => $this->eb->model,
65-
"loadApp" => $map[$loadApp]
90+
"loadApp" => $map[$loadApp],
91+
"isV3" => $this->eb->isV3,
92+
"version" => $this->eb->version,
93+
"phpNamespace" => $this->eb->config['phpNamespace'],
94+
"cmpNamespace" => $this->config['namespace']
6695
];
6796

6897
// Merge request properties into placeholders
@@ -117,6 +146,6 @@ public function getTemplatesPaths($coreOnly = false)
117146
*/
118147
public function getLanguageTopics()
119148
{
120-
return ['ExtraBuilder:default'];
149+
return [$this->eb->config['lexiconKey'].':default'];
121150
}
122151
}

0 commit comments

Comments
 (0)