Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/11.2' into 11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjia90 committed Apr 23, 2024
2 parents a44e05b + 8fbf454 commit d44ada0
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/ci/files/public/index_test.php
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;

include __DIR__ . "/../vendor/autoload_runtime.php";
include __DIR__ . "/../vendor/autoload.php";

define('PIMCORE_PROJECT_ROOT', __DIR__ . '/..');
define('APP_ENV', 'test');
Expand All @@ -43,3 +43,4 @@
$response->send();

$kernel->terminate($request, $response);

1 change: 1 addition & 0 deletions bin/pimcore-install
Expand Up @@ -43,6 +43,7 @@ if (file_exists($a = getcwd() . '/vendor/autoload.php')) {

define('PIMCORE_PROJECT_ROOT', $projectRoot);

Bootstrap::$isInstaller = true;
Bootstrap::bootstrap();

Debug::enable();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -139,7 +139,7 @@
"codeception/codeception": "^5.0.3",
"codeception/module-symfony": "^3.1.0",
"ergebnis/phpstan-rules": "^2.0",
"phpstan/phpstan": "1.10.66",
"phpstan/phpstan": "1.10.67",
"phpstan/phpstan-symfony": "^1.3.5",
"phpunit/phpunit": "^9.3",
"gotenberg/gotenberg-php": "^1.1 || ^2.0",
Expand Down
28 changes: 25 additions & 3 deletions lib/Bootstrap.php
Expand Up @@ -27,6 +27,11 @@

class Bootstrap
{
/**
* @internal
*/
public static bool $isInstaller = false;

public static function startup(): Kernel|\App\Kernel|KernelInterface
{
self::setProjectRoot();
Expand All @@ -44,7 +49,6 @@ public static function startupCli(): Kernel|KernelInterface
}

self::setProjectRoot();

self::bootstrap();

$workingDirectory = getcwd();
Expand Down Expand Up @@ -100,16 +104,34 @@ public static function setProjectRoot(): void
public static function bootstrap(): void
{
$isCli = in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true);
if (!Tool::hasCurrentRequest() && !$isCli) {

// BC Layer when using the public/index.php without symfony runtime pimcore/skeleton #128 OR without pimcore/skeleton #183 (< 11.0.4)
if (!Tool::hasCurrentRequest() && !$isCli && !isset($_ENV['SYMFONY_DOTENV_VARS'])) {
trigger_deprecation(
'pimcore/skeleton',
'11.2.0',
'For consistency purpose, it is recommended to use the autoload from Symfony Runtime.
'For consistency purpose, it is recommended to use the autoload from Symfony Runtime.
When using it, the line "Bootstrap::bootstrap();" in `public/index.php` should be moved just above "$kernel = Bootstrap::kernel();" and within the closure'
);
self::bootDotEnvVariables();
}

// BC Layer when using bin/console without symfony runtime, exclude installer script
if ($isCli && !isset($_ENV['SYMFONY_DOTENV_VARS']) && !self::$isInstaller) {
trigger_deprecation(
'pimcore/skeleton',
'11.2.0',
'For consistency purpose, it is recommended to use the autoload from Symfony Runtime in project root "bin/console"'
);
self::bootDotEnvVariables();
}

// Installer
// Keep this block unless core is requiring symfony runtime as mandatory and pimcore-install is adapted
if ($isCli && !isset($_ENV['SYMFONY_DOTENV_VARS']) && self::$isInstaller) {
self::bootDotEnvVariables();
}

self::defineConstants();

// load a startup file if it exists - this is a good place to preconfigure the system
Expand Down
Expand Up @@ -40,6 +40,9 @@ public function unmarshal(mixed $value, array $params = []): ?array
{
if (is_array($value)) {
$rgb = $value['value'];
if (!$rgb) {
return null;
}
$a = $value['value2'];
[$r, $g, $b] = sscanf($rgb, '%02x%02x%02x');
$a = hexdec($a);
Expand Down
46 changes: 45 additions & 1 deletion models/DataObject/Classificationstore/Dao.php
Expand Up @@ -65,7 +65,17 @@ public function save(): void
$items = $this->model->getItems();
$activeGroups = $this->model->getActiveGroups();

$collectionMapping = $this->model->getGroupCollectionMappings();
$collectionMapping = $collectionToAdd = $this->model->getGroupCollectionMappings();

// when the field is inheritable, check the parent collection mappings and skip the ones that are meant to be inherited
$allowInherit = $this->model->getClass()->getAllowInherit();

// check and exclude if an object is the top of the hierarchy
// otherwise it wouldn't be able to distinguish whether the exact collections are from itself, rather from a common parent
if ($allowInherit && DataObject\Service::hasInheritableParentObject($object)) {
$parentCollectionMapping = DataObject\Service::useInheritedValues(true, $this->model->getGroupCollectionMappings(...));
$collectionToAdd = array_diff($collectionToAdd, $parentCollectionMapping);
}

$groupsTable = $this->getGroupsTableName();

Expand All @@ -86,6 +96,9 @@ public function save(): void
}
}

$alreadySavedGroups = [];
$alreadySavedKeyIds = [];

foreach ($items as $groupId => $group) {
foreach ($group as $keyId => $keyData) {
if (!isset($activeGroups[$groupId])) {
Expand Down Expand Up @@ -130,6 +143,37 @@ public function save(): void
$data['value2'] = $encodedData['value2'] ?? null;

Helper::upsert($this->db, $dataTable, $data, $this->getPrimaryKey($dataTable));
$alreadySavedGroups[] = $groupId;
$alreadySavedKeyIds[] = $keyId;
}
}
}

// Adds a placeholder to persist collectionId by adding the first field of the group
// that belongs to a collection with NULL values
foreach ($collectionToAdd as $groupId => $collectionId) {
// Ignore the groups that are already saved and those without any collection id
if ($collectionId && !in_array($groupId, $alreadySavedGroups)) {
$group = GroupConfig::getById($groupId);
$groupKeys = $group->getRelations();
// make sure that any of the group keys are not among those already saved
// if so, skip as there no need for a placeholder
if (!in_array(array_keys($groupKeys), $alreadySavedKeyIds)) {
$firstKey = reset($groupKeys);
$keyId = $firstKey->getKeyId();
$keyConfig = DefinitionCache::get($keyId);
$data = [
'id' => $objectId,
'collectionId' => $collectionId,
'groupId' => $groupId,
'keyId' => $keyId,
'fieldname' => $fieldname,
'language' => 'default',
'type' => $keyConfig->getType(),
'value' => null,
'value2' => null,
];
$this->db->insert($dataTable, $data);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/DataObject/Service.php
Expand Up @@ -1506,7 +1506,7 @@ public static function getCalculatedFieldValueForEditMode(Concrete $object, arra
case DataObject\ClassDefinition\Data\CalculatedValue::CALCULATOR_TYPE_EXPRESSION:

try {
return self::evaluateExpression($fd, $object, $data);
return (string) self::evaluateExpression($fd, $object, $data);
} catch (SyntaxError $exception) {
return $exception->getMessage();
}
Expand Down
8 changes: 4 additions & 4 deletions tests/_bootstrap.php
Expand Up @@ -16,12 +16,12 @@

use Pimcore\Tests\Support\Util\Autoloader;

if (file_exists(__DIR__ . '/../vendor/autoload_runtime.php')) {
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
define('PIMCORE_PROJECT_ROOT', __DIR__ . '/..');
} elseif (file_exists(__DIR__ . '/../../../../vendor/autoload_runtime.php')) {
} elseif (file_exists(__DIR__ . '/../../../../vendor/autoload.php')) {
define('PIMCORE_PROJECT_ROOT', __DIR__ . '/../../../..');
} elseif (getenv('PIMCORE_PROJECT_ROOT')) {
if (file_exists(getenv('PIMCORE_PROJECT_ROOT') . '/vendor/autoload_runtime.php')) {
if (file_exists(getenv('PIMCORE_PROJECT_ROOT') . '/vendor/autoload.php')) {
define('PIMCORE_PROJECT_ROOT', getenv('PIMCORE_PROJECT_ROOT'));
} else {
throw new \Exception('Invalid Pimcore project root "' . getenv('PIMCORE_PROJECT_ROOT') . '"');
Expand All @@ -30,7 +30,7 @@
throw new \Exception('Unknown configuration! Pimcore project root not found, please set env variable PIMCORE_PROJECT_ROOT.');
}

include PIMCORE_PROJECT_ROOT . '/vendor/autoload_runtime.php';
include PIMCORE_PROJECT_ROOT . '/vendor/autoload.php';
\Pimcore\Bootstrap::setProjectRoot();
\Pimcore\Bootstrap::bootstrap();

Expand Down

0 comments on commit d44ada0

Please sign in to comment.