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

Attempted to load class "IntegrationConfiguration" #114

Open
mage-monk opened this issue Aug 18, 2021 · 6 comments
Open

Attempted to load class "IntegrationConfiguration" #114

mage-monk opened this issue Aug 18, 2021 · 6 comments

Comments

@mage-monk
Copy link

Using Pimcore 6.0

composer require divante-ltd/pimcore-magento2-bridge:dev-develop-v2

getting below error :

Attempted to load class "IntegrationConfiguration" from namespace "Pimcore\Model\DataObject".
Did you forget a "use" statement for "Divante\MagentoIntegrationBundle\Domain\DataObject\IntegrationConfiguration"?

image

@mage-monk
Copy link
Author

Do we have solution to fix this?

@mage-monk
Copy link
Author

Made the changes in installer.php and it worked for me

* @copyright Copyright (c) 2018 DIVANTE (https://divante.co) */ namespace Divante\MagentoIntegrationBundle\Migrations; use Divante\MagentoIntegrationBundle\Domain\IntegrationConfiguration\IntegrationHelper; use Doctrine\DBAL\Migrations\Version; use Doctrine\DBAL\Schema\Schema; use Pimcore\Cache; use Pimcore\Db\Connection; use Pimcore\Extension\Bundle\Installer\MigrationInstaller; use Pimcore\Migrations\MigrationManager; use Pimcore\Model\DataObject; use Pimcore\Model\Property\Predefined; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\Process\Process; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\ClassDefinition\Service; /** * Class Installer * @Package Divante\MagentoIntegrationBundle\Migrations */ class Installer extends MigrationInstaller { const CONFIGURATION_CLASS_NAME = 'IntegrationConfiguration'; /** @var FileLocator */ protected $fileLocator; private $installSourcesPath; /** * @var array */ private $classesToInstall = [ 'IntegrationConfiguration' => 'IntegrationConfiguration' ]; /** * @param BundleInterface $bundle * @param Connection $connection * @param MigrationManager $migrationManager * @param FileLocator $fileLocator */ public function __construct( BundleInterface $bundle, Connection $connection, MigrationManager $migrationManager, FileLocator $fileLocator ) { $this->fileLocator = $fileLocator; $this->installSourcesPath = __DIR__ . '/../Resources/install'; parent::__construct($bundle, $connection, $migrationManager); } /** * @param Schema $schema * @param Version $version */ public function migrateInstall(Schema $schema, Version $version): void { if (!Predefined::getByKey(IntegrationHelper::PRODUCT_TYPE_CONFIGURABLE_ATTRIBUTE) instanceof Predefined) { $propertyData = [ 'name' => 'Configurable Attributes', 'key' => IntegrationHelper::PRODUCT_TYPE_CONFIGURABLE_ATTRIBUTE, 'ctype' => 'object', 'type' => 'text', 'inheritable' => true ]; $property = Predefined::create(); $property->setValues($propertyData); $property->save(); } Cache::disable(); $this->installClasses(); // $classDefinition = $this->locateClassDefinitionFile(); // $command = ['bin/console', 'pimcore:definition:import:class', $classDefinition]; // $process = new Process($command, PIMCORE_PROJECT_ROOT); // $process->setTimeout(0); // $process->run(); // $this->outputWriter->write($process->getOutput()); Cache::enable(); if (!file_exists(PIMCORE_LOG_DIRECTORY . '/magento2-connector')) { mkdir(PIMCORE_LOG_DIRECTORY . '/magento2-connector', 0740); } $this->createSampleObject(); } /** * @return string */ protected function locateClassDefinitionFile(): string { $filename = '@DivanteMagentoIntegrationBundle/Resources/install/classes/class_IntegrationConfiguration_export.json'; return $this->fileLocator->locate($filename); } protected function createSampleObject() { $object = new DataObject\IntegrationConfiguration(); $object->setParent(DataObject\Service::createFolderByPath('/integration-configuration')); $object->setPublished(false); $object->setOmitMandatoryCheck(true); $object->setKey('magento-configuration'); $object->save(); } private function getClassesToInstall(): array { $result = []; foreach (array_keys($this->classesToInstall) as $className) { $filename = sprintf('class_%s_export.json', $className); $path = $this->installSourcesPath . '/classes/' . $filename; $path = realpath($path); if (false === $path || !is_file($path)) { throw new AbortMigrationException(sprintf( 'Class export for class "%s" was expected in "%s" but file does not exist', $className, $path )); } $result[$className] = $path; } return $result; } private function installClasses() { $classes = $this->getClassesToInstall(); $mapping = $this->classesToInstall; foreach ($classes as $key => $path) { $class = ClassDefinition::getByName($key); if ($class) { $this->outputWriter->write(sprintf( ' WARNING: Skipping class "%s" as it already exists', $key )); continue; } $class = new ClassDefinition(); $classId = $mapping[$key]; $class->setName($key); $class->setId($classId); $data = file_get_contents($path); $success = Service::importClassDefinitionFromJson($class, $data, false, true); if (!$success) { throw new AbortMigrationException(sprintf( 'Failed to create class "%s"', $key )); } } } /** * @param Schema $schema * @param Version $version */ public function migrateUninstall(Schema $schema, Version $version): void { Cache::disable(); $class = DataObject\ClassDefinition::getByName(static::CONFIGURATION_CLASS_NAME); if ($class) { $class->delete(); } Cache::enable(); rmdir(PIMCORE_LOG_DIRECTORY . '/magento2-connector'); } }

@prugala
Copy link
Contributor

prugala commented Aug 19, 2021

@prince0212 Could you create Pull Request with changes?

@mage-monk
Copy link
Author

sure will do the needful

@jantomicky
Copy link

jantomicky commented Feb 8, 2022

I am getting the same error on an already running instance (since 2020). After running composer update and attempting to edit existing configuration object in the Pimcore UI / admin:

Attempted to load class "IntegrationConfiguration" from namespace "Divante\MagentoIntegrationBundle\Model\DataObject". Did you forget a "use" statement for another namespace?

I can't access the configuration object, as the error breaks the Pimcore UI. Doesn't look like namespacing is the problem here? This is on PHP 7.4 and Symfony 4.4 so this could be namespacing / autoloading issue(?)

@jantomicky
Copy link

Related to #105 and #110, the package does not comply with PSR-4, so Composer 2 won't autoload the necessary classes.
A fix has been commited to the develop-v2 branch only.
An easy solution is to downgrade Composer to V1 (composer self-update --1) and running composer update, then all classes autoload properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants