Add LEGACY_PATH constant to define the path to the legacy application

This commit is contained in:
Dillon-Brown 2019-12-24 13:26:51 +00:00
parent 471adea58e
commit f27aee78e5
4 changed files with 121 additions and 9 deletions

113
bin/cli Executable file
View file

@ -0,0 +1,113 @@
#!/usr/bin/env php
<?php
define('BASE_PATH', dirname(__DIR__) . '/');
define('APP_PATH', dirname(__DIR__) . '/core/modules');
define('LEGACY_PATH', __DIR__ . '/legacy/');
require BASE_PATH . 'vendor/autoload.php';
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DBALException;
use Doctrine\ORM\Events;
use Doctrine\ORM\ORMException;
use SuiteCRM\Core\Base\Config\Manager as ConfigManager;
use SuiteCRM\Core\Base\Helper\File\File;
use SuiteCRM\Core\Base\Cli\CommandMapper;
use Symfony\Component\Console\Application;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver;
if (count($argv) === 1 && $argv[0] === 'bin/cli') {
echo
"
\033[38;5;167m OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO\033[38;5;240m00000000000000000000000000000000000000000
\033[38;5;167m OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO\033[38;5;240m00000\033[1;37m000000\033[38;5;240m00\033[1;37m0000000\033[38;5;240m00000\033[1;37m000\033[38;5;240m000000000\033[1;37m000\033[38;5;240mG00
\033[38;5;167m OOOG\033[1;37m000\033[38;5;167mGOOO\033[1;37m0\033[38;5;167mOOOO\033[1;37m0\033[38;5;167mOOC\033[1;37m0\033[38;5;167mOOC\033[1;37m00000\033[38;5;167mGOC\033[1;37m0000\033[38;5;167mOOO\033[38;5;240m\033[38;5;240m0000\033[1;37m00000\033[38;5;240mG0000\033[1;37m000\033[38;5;240m000C\033[1;37m00\033[38;5;240m00C\033[1;37m00\033[38;5;240m0\033[1;37m0\033[38;5;240m0000000\033[1;37m0\033[38;5;240m0\033[1;37m00\033[38;5;240mG00
\033[38;5;167m OOG\033[1;37m0\033[38;5;167mCOOOOOO\033[1;37m0\033[38;5;167mOOOO\033[1;37m0\033[38;5;167mOOC\033[1;37m0\033[38;5;167mOOOOC\033[1;37m0\033[38;5;167mGOOOC\033[1;37m0\033[38;5;167mGOOOO\033[38;5;240m0000\033[1;37m0000\033[38;5;240mC000000\033[1;37m000\033[38;5;240m0000G\033[1;37m0\033[38;5;240m00C\033[1;37m00\033[38;5;240m0\033[1;37m00\033[38;5;240m00000\033[1;37m00\033[38;5;240m0\033[1;37m00\033[38;5;240mG00
\033[38;5;167m OOOC\033[1;37m00\033[38;5;167mCOOOO\033[1;37m0\033[38;5;167mOOOO\033[1;37m0\033[38;5;167mOOC\033[1;37m0\033[38;5;167mOOOOC\033[1;37m0\033[38;5;167mGOOOC\033[1;37m000\033[38;5;167mOOO\033[38;5;240m000C\033[1;37m0000\033[38;5;240mG000000\033[1;37m000\033[38;5;240m000C\033[1;37m00\033[38;5;240m00C\033[1;37m00\033[38;5;240m00\033[1;37m00\033[38;5;240m000\033[1;37m00\033[38;5;240m00\033[1;37m00\033[38;5;240mG00
\033[38;5;167m OOOOOOC\033[1;37m0\033[38;5;167mOOO\033[1;37m0\033[38;5;167mOOO\033[1;37m00\033[38;5;167mOOC\033[1;37m0\033[38;5;167mOOOOC\033[1;37m0\033[38;5;167mGOOOC\033[1;37m0\033[38;5;167mGOOOO\033[38;5;240m0000\033[1;37m0000\033[38;5;240mC000000\033[1;37m00000000\033[38;5;240m000C\033[1;37m00\033[38;5;240m00C\033[1;37m00\033[38;5;240m0\033[1;37m00\033[38;5;240m000\033[1;37m00\033[38;5;240mG00
\033[38;5;167m OOOC\033[1;37m000\033[38;5;167mCOOOG\033[1;37m0000\033[38;5;167mGOOC\033[1;37m0\033[38;5;167mOOOOC\033[1;37m0\033[38;5;167mGOOOC\033[1;37m0000\033[38;5;167mOOO\033[38;5;240m0000\033[1;37m00000\033[38;5;240mG0000\033[1;37m000\033[38;5;240m000C\033[1;37m00\033[38;5;240m00C\033[1;37m00\033[38;5;240m000C\033[1;37m000\033[38;5;240m0000\033[1;37m00\033[38;5;240mG00
\033[38;5;167m OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO\033[38;5;240m0000G\033[1;37m000000\033[38;5;240m00\033[1;37m000\033[38;5;240m0000G\033[1;37m00\033[38;5;240m0C\033[1;37m00\033[38;5;240m00000000000\033[1;37m00\033[38;5;240mG00
\033[38;5;167m OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO\033[38;5;240m00000000000000000000000000000000000000000\033[1;37m
";
}
$application = new Application('Version 1.0');
$configManager = new ConfigManager();
try {
$appConfig = $configManager->loadFiles(BASE_PATH . 'config/config.yml');
} catch (Exception $e) {
trigger_error('CLI failed to load files: ' . $e);
}
if ($appConfig->has('storage.mysql')) {
$connectionParams = $appConfig->get('storage.mysql');
$namespaces = $appConfig->get('entity.namespaces');
$driver = new SimplifiedYamlDriver($namespaces);
$isDevMode = false;
if ($appConfig->has('server.environment') && $appConfig->get('server.environment') === 'develop') {
$isDevMode = true;
}
$config = Setup::createYAMLMetadataConfiguration($namespaces, $isDevMode);
$cache = new ArrayCache();
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$config->setMetadataDriverImpl($driver);
// Table Prefix
$evm = new EventManager();
$tablePrefix = new SuiteCRM\Core\Base\Module\Storage\TablePrefix('suite8_');
$evm->addEventListener(Events::loadClassMetadata, $tablePrefix);
try {
$entityManager = EntityManager::create($connectionParams, $config, $evm);
} catch (ORMException $e) {
trigger_error('CLI failed to get create entity manager instance: ' . $e);
}
//-- This I had to add to support the Mysql enum type.
try {
$platform = $entityManager->getConnection()->getDatabasePlatform();
} catch (DBALException $e) {
trigger_error('CLI failed to get DB platform: ' . $e);
}
try {
$platform->registerDoctrineTypeMapping('enum', 'string');
} catch (DBALException $e) {
trigger_error('CLI failed to get register doctrine type mapping: ' . $e);
}
$helperSet = ConsoleRunner::createHelperSet($entityManager);
}
$configPath = [BASE_PATH . 'config/config.yml', BASE_PATH . 'core/base/Config/modules.config.yml'];
$fileHelper = new File();
$commandMapper = new CommandMapper($fileHelper, $configManager, $configPath);
$application->setHelperSet($helperSet);
$application->addCommands($commandMapper->getAllCommands());
ConsoleRunner::addCommands($application);
// Run Console Application
try {
$application->run();
} catch (Exception $e) {
trigger_error('Application run failure: ' . $e);
}

View file

@ -15,8 +15,8 @@ class LegacyHandler
*/
public function runLegacyEntryPoint(): bool
{
if (!defined('BASE_PATH')) {
define('BASE_PATH', dirname(__DIR__, 2) . '/');
if (!defined('LEGACY_PATH')) {
define('LEGACY_PATH', dirname(__DIR__, 2) . '/legacy/');
}
// Set up sugarEntry
@ -24,14 +24,12 @@ class LegacyHandler
define('sugarEntry', true);
}
$legacyPath = realpath(BASE_PATH . '/legacy');
// Set working directory for legacy
chdir($legacyPath);
chdir(LEGACY_PATH);
// Load in legacy
require_once 'include/MVC/preDispatch.php';
require_once 'include/entryPoint.php';
require_once LEGACY_PATH . 'include/MVC/preDispatch.php';
require_once LEGACY_PATH . 'include/entryPoint.php';
return true;
}

View file

@ -24,7 +24,7 @@ class Navbar extends LegacyHandler
'submenu' => [],
];
require 'include/globalControlLinks.php';
require LEGACY_PATH . 'include/globalControlLinks.php';
foreach ($global_control_links as $key => $value) {
if ($key === 'users') {
@ -77,4 +77,4 @@ class Navbar extends LegacyHandler
throw new \RuntimeException('Running legacy entry point failed');
}
}
}

View file

@ -15,6 +15,7 @@ header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Ac
// Get the Application Path
define('BASE_PATH', __DIR__);
define('APP_PATH', __DIR__ . '/core/modules/');
define('LEGACY_PATH', __DIR__ . '/legacy/');
// Get the autoloader class
require BASE_PATH . '/vendor/autoload.php';