core icon indicating copy to clipboard operation
core copied to clipboard

MongoDB class existence check is out of date (with PHP7.0)

Open GodStorm91 opened this issue 5 years ago • 4 comments

PHP MongoDB Driver has been updated in 2016, the old client class Mongo is deprecated.

https://derickrethans.nl/new-drivers.html

But we still have this check in our core MongoDB class. Should we change it

		if ( ! class_exists('Mongo'))
		{
			throw new \Mongo_DbException("The MongoDB PECL extension has not been installed or enabled");
		}

The new check should be

		if ( ! class_exists('Mongo') && ! class_exists('MongoDB\Client'))
		{
			throw new \Mongo_DbException("The MongoDB PECL extension has not been installed or enabled");
		}

By the way, I think in the near future we should remove the ! class_exists('Mongo') check too.

GodStorm91 avatar May 10 '19 06:05 GodStorm91

That is assuming the new MongoDB\Client class has exactly the same API als the old Mongo class. Is that the case? If not, the entire abstraction layer has to be rewritten, in which case you'd probably be better of using an external Mongo library.

WanWizard avatar May 10 '19 11:05 WanWizard

Thank you for your reply. Currently we have to override the core class and override some methods to match with the new MongoDB Client. Actually some methods in the driver have been changed, and I think the best solution is to write a new Abstraction Driver or using an external library.

GodStorm91 avatar May 13 '19 03:05 GodStorm91

Is your class override complete? i.e. do all methods available work with the new MongoDB Client, or did you just override the methods you use?

I am willing to try and find the time to add the abstraction, but I am not a Mongo user, if you have complete code and willing to donate it?

WanWizard avatar May 13 '19 11:05 WanWizard

currently we only override only some methods we used. But I think I will check remaining methods whether they need to be changed or not. I will share my complete code after I finish :)

GodStorm91 avatar May 16 '19 04:05 GodStorm91