Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[All] fixes for Pimcore 5.7 #869

Merged
merged 4 commits into from
Mar 16, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[All] fixes for Pimcore 5.7
  • Loading branch information
dpfaffenbauer committed Mar 16, 2019
commit 0cfa900f3938e86ada20c08b810cfaf6db6ed9c4
11 changes: 3 additions & 8 deletions src/CoreShop/Bundle/CoreBundle/CoreExtension/StorePrice.php
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
use CoreShop\Component\Core\Model\StoreInterface;
use CoreShop\Component\Core\Repository\ProductStorePriceRepositoryInterface;
use CoreShop\Component\Pimcore\BCLayer\CustomResourcePersistingInterface;
use CoreShop\Component\Pimcore\BCLayer\LazyLoadedFields;
use CoreShop\Component\Store\Repository\StoreRepositoryInterface;
use Pimcore\Model;

@@ -234,7 +235,7 @@ public function preGetData($object, $params = [])
}

if ($object instanceof Model\DataObject\Concrete) {
if (!in_array($this->getName(), $object->getO__loadedLazyFields())) {
if (!LazyLoadedFields::hasLazyKey($object, $this->getName())) {
$data = $this->load($object, ['force' => true]);

//TODO: Remove once CoreShop requires min Pimcore 5.5
@@ -581,13 +582,7 @@ protected function markAsLoaded($object)
return;
}

if (method_exists($this, 'markLazyloadedFieldAsLoaded')) {
$this->markLazyloadedFieldAsLoaded($object);
} else {
if (!in_array($this->getName(), $object->getO__loadedLazyFields())) {
$object->addO__loadedLazyField($this->getName());
}
}
LazyLoadedFields::addLazyKey($object, $this->getName());
}

/**
12 changes: 6 additions & 6 deletions src/CoreShop/Bundle/IndexBundle/Worker/MysqlWorker.php
Original file line number Diff line number Diff line change
@@ -295,12 +295,12 @@ public function deleteIndexStructures(IndexInterface $index)
$languages = Tool::getValidLanguages();

foreach ($languages as $language) {
$this->database->query('DROP VIEW IF EXISTS `' . $this->getLocalizedViewName($index, $language) . '`');
$this->database->executeQuery('DROP VIEW IF EXISTS `' . $this->getLocalizedViewName($index, $language) . '`');
}

$this->database->query('DROP TABLE IF EXISTS `' . $this->getTablename($index) . '`');
$this->database->query('DROP TABLE IF EXISTS `' . $this->getLocalizedTablename($index) . '`');
$this->database->query('DROP TABLE IF EXISTS `' . $this->getRelationTablename($index) . '`');
$this->database->executeQuery('DROP TABLE IF EXISTS `' . $this->getTablename($index) . '`');
$this->database->executeQuery('DROP TABLE IF EXISTS `' . $this->getLocalizedTablename($index) . '`');
$this->database->executeQuery('DROP TABLE IF EXISTS `' . $this->getRelationTablename($index) . '`');
} catch (\Exception $e) {
$this->logger->error($e);
}
@@ -377,7 +377,7 @@ protected function doInsertData(IndexInterface $index, $data)
$insert = 'INSERT INTO ' . $this->getTablename($index) . ' (' . implode(',', array_keys($dataKeys)) . ') VALUES (' . implode(',', $dataKeys) . ')'
. ' ON DUPLICATE KEY UPDATE ' . implode(',', $insertStatement);

$this->database->query($insert, array_merge($updateData, $insertData));
$this->database->executeQuery($insert, array_merge($updateData, $insertData));
}

/**
@@ -417,7 +417,7 @@ protected function doInsertLocalizedData(IndexInterface $index, $data)
$insert = 'INSERT INTO ' . $this->getLocalizedTablename($index) . ' (' . implode(',', array_keys($dataKeys)) . ') VALUES (' . implode(',', $dataKeys) . ')'
. ' ON DUPLICATE KEY UPDATE ' . implode(',', $insertStatement);

$this->database->query($insert, array_merge($updateData, $insertData));
$this->database->executeQuery($insert, array_merge($updateData, $insertData));
}
}

Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
use CoreShop\Component\Order\Model\SaleInterface;
use CoreShop\Component\Order\Model\SaleItemInterface;
use CoreShop\Component\Order\Notes;
use CoreShop\Component\Pimcore\BCLayer\GridHelper;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
use CoreShop\Component\Store\Model\StoreInterface;
use CoreShop\Component\Taxation\Model\TaxItemInterface;
@@ -49,7 +50,7 @@ public function listAction(Request $request)

if ($request->get('filter', null)) {
$conditionFilters = [];
$conditionFilters[] = DataObject\Service::getFilterCondition($request->get('filter'), DataObject\ClassDefinition::getByName($this->getParameter($this->getSaleClassName())));
$conditionFilters[] = GridHelper::getFilterCondition($request->get('filter'), DataObject\ClassDefinition::getByName($this->getParameter($this->getSaleClassName())));
if (count($conditionFilters) > 0 && $conditionFilters[0] !== '(())') {
$list->setCondition(implode(' AND ', $conditionFilters));
}
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@

use CoreShop\Bundle\ProductBundle\Form\Type\ProductSpecificPriceRuleType;
use CoreShop\Component\Pimcore\BCLayer\CustomResourcePersistingInterface;
use CoreShop\Component\Pimcore\BCLayer\LazyLoadedFields;
use CoreShop\Component\Product\Model\ProductInterface;
use CoreShop\Component\Product\Model\ProductSpecificPriceRuleInterface;
use CoreShop\Component\Product\Repository\ProductSpecificPriceRuleRepositoryInterface;
@@ -108,11 +109,11 @@ public function preGetData($object)
$data = $object->{$this->getName()};
}

if (!method_exists($object, 'getO__loadedLazyFields')) {
/*if (!method_exists($object, 'getO__loadedLazyFields')) {
return $data;
}
}*/

if (!in_array($this->getName(), $object->getO__loadedLazyFields())) {
if (!LazyLoadedFields::hasLazyKey($object, $this->getName())) {
$data = $this->load($object, ['force' => true]);

$setter = 'set' . ucfirst($this->getName());
@@ -129,8 +130,8 @@ public function preGetData($object)
*/
public function preSetData($object, $data, $params = [])
{
if (!in_array($this->getName(), $object->getO__loadedLazyFields())) {
$object->addO__loadedLazyField($this->getName());
if (!LazyLoadedFields::hasLazyKey($object, $this->getName())) {
LazyLoadedFields::addLazyKey($object, $this->getName());
}

return $data;
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public function installResources(OutputInterface $output, $applicationName = nul
foreach ($sqlFilesToExecute as $sqlFile) {
$progress->setMessage(sprintf('<error>Execute SQL File %s</error>', $sqlFile));

$db->query(file_get_contents($this->kernel->locateResource($sqlFile)));
$db->executeQuery(file_get_contents($this->kernel->locateResource($sqlFile)));

$progress->advance();
}
41 changes: 41 additions & 0 deletions src/CoreShop/Component/Pimcore/BCLayer/GridHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Component\Pimcore\BCLayer;

use Pimcore\Bundle\AdminBundle\Helper\GridHelperService;
use Pimcore\Model\DataObject\Service;

class GridHelper
{
public static function getFilterCondition($filterJson, $class)
{
if (class_exists(GridHelperService::class)) {
$gridHelper = new GridHelperService();
return $gridHelper->getFilterCondition($filterJson, $class);
}

$serviceClass = Service::class;

if (method_exists($serviceClass, 'getFilterCondition')) {
return $serviceClass::getFilterCondition($filterJson, $class);
}

throw new \InvalidArgumentException(
sprintf(
'Expected class %s to exist or method %s:getFilterCondition to exist',
GridHelperService::class,
Service::class
)
);
}
}
56 changes: 56 additions & 0 deletions src/CoreShop/Component/Pimcore/BCLayer/LazyLoadedFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Component\Pimcore\BCLayer;

use Pimcore\Model\DataObject\LazyLoadedFieldsInterface;

class LazyLoadedFields
{
public static function hasLazyKey($object, $key)
{
if (interface_exists(LazyLoadedFieldsInterface::class) && $object instanceof LazyLoadedFieldsInterface) {
return $object->hasLazyKey($key);
}

if (method_exists($object, 'getO__loadedLazyFields')) {
return in_array($key, $object->getO__loadedLazyFields());
}

throw new \InvalidArgumentException(
sprintf(
'Expected Object of Type "%s" to be either of interface LazyLoadedFieldsInterface or to have the method getO__loadedLazyFields',
get_class($object)
)
);
}

public static function addLazyKey($object, $key)
{
if (interface_exists(LazyLoadedFieldsInterface::class) && $object instanceof LazyLoadedFieldsInterface) {
$object->addLazyKey($key);
return;
}

if (method_exists($object, 'addO__loadedLazyField')) {
$object->addO__loadedLazyField($key);
return;
}

throw new \InvalidArgumentException(
sprintf(
'Expected Object of Type "%s" to be either of interface LazyLoadedFieldsInterface or to have the method addO__loadedLazyField',
get_class($object)
)
);
}
}
6 changes: 3 additions & 3 deletions src/CoreShop/Component/Pimcore/DataObject/Migrate.php
Original file line number Diff line number Diff line change
@@ -207,15 +207,15 @@ public static function migrateData($oldPimcoreClass, $newPimcoreClass)

$sql = "INSERT INTO $newSqlTable SELECT " . implode(',', $columns) . " FROM $oldSqlTable";

$db->query($sql);
$db->executeQuery($sql);

if ($replaceClassNames) {
$sql = "UPDATE $newSqlTable SET oo_classId=?, oo_className=?";

$db->query($sql, [$newClassDefinition->getId(), $newClassDefinition->getName()]);
$db->executeQuery($sql, [$newClassDefinition->getId(), $newClassDefinition->getName()]);
}
}

$db->query('UPDATE objects SET o_classId=?, o_className=? WHERE o_classId=?', [$newClassDefinition->getId(), $newClassDefinition->getName(), $oldClassDefinition->getId()]);
$db->executeQuery('UPDATE objects SET o_classId=?, o_className=? WHERE o_classId=?', [$newClassDefinition->getId(), $newClassDefinition->getName(), $oldClassDefinition->getId()]);
}
}