Magento Custom Api v2 resource path not callable when compilation mode enabled - php

The custom api function call fails with error message "Resource path not callable" after compilation is enabled. The custom api works as expected when compilation is not enabled.
Question
Is it possible to configure a custom Magento api so that it can be called when both compilation is disabled AND enabled in versions 1.5 and above?
2 workarounds will succeed with compilation enabled :
Workaround #1:
Rename the compiled file from (lowercase the v in V2):
/includes/src/MyApi_Test_Model_Objectmodel_Api_V2.php
to
/includes/src/MyApi_Test_Model_Objectmodel_Api_v2.php
Note: this must be executed after compilation is enabled, and done each time compilation occurs
Workaround #2:
Rename the original V2.php file to v2.php in :
/app/code/local/MyApi/Test/Model/Objectmodel/Api/V2.php
Note: this will fix the api function to succeed 100% of the time when compilation is enabled, but removing the V2.php will break the v2 usage when compilation is disabled. Having BOTH a V2.php and a v2.php will fix both scenarios, but it appears that the 2 files cannot be bundled together for deployment (in addition to not being DRY).
EDIT
Adding more details.
I've traced the execution and issue using this very helpful answer, and have come to the following conclusions (all code is taken from version 1.9.1.0 CE):
The V2.php is searched for in the includes/src directory as /includes/src/MyApi_Test_Model_Objectmodel_Api_v2.php.
The "call" function in /var/www/html/includes/src/Mage_Api_Model_Server_Handler_Abstract.php contains the following line :
$modelName = $this->_prepareResourceModelName((string) $resources->$resourceName->model);
and _prepareResourceModelName will append the _resourceSuffix, if it exists, which in this case is '_v2' because it is called in :
/app/code/core/Mage/Api/Model/Server/V2/Handler.php
protected $_resourceSuffix = '_v2';
The output becomes :
$resources->$resourceName->model=MyApi_Test_Model_Objectmodel_Api
modelName : MyApi_Test_Model_Objectmodel_Api_v2

but removing the V2.php will break the v2 usage when compilation is disabled
The right thing to do here is to fix your extension so it works with the class file named V2.php. Uppercased word segments (i.e. Uppercase_Word_Segments are Magento's standard for class names, and using a different convention will likely cause other problems.

Related

Error and warning connecting MongoDB to PHP using php_mongodb extension

I installed the MongoDB PHP driver on Windows 10 (I'm using WAMP equipped with PHP 5.6.25. following the istructions I found at http://php.net/manual/en/mongodb.installation.windows.php and I installed also the libbson and libmongoc libraries (requested as requirements) as written at http://php.net/manual/en/mongodb.requirements.php.
Then, I added the bin folders of MongoDB, libbson and libmongoc to system path.
However, even if I can see the php_mongodb extension in the extensions list of WAMP, launching phpinfo() the mongo extension doesn't appear with the others.
Furthermore, tryng to connect to my database with
<?php
$mongo=new MongoClient("");
$db=$mongo->galileo;
$collection= $db->items;
print_r("Number of documens: "); ?>
I got the error
Fatal error: Class 'MongoClient' not found in C:\wamp64\www\galileo\index.php >on line 21
At a first look, reading this error, it might seem like that PHP is looking for php_mongodb extension in the uncorrect folder i.e. C:\wamp64\www\galileo\index.php (where the index page of my project is placed) instead of the correct one C:\wamp64\bin\php\php5.6.25\ext where all the extensions are.
But, looking at php log file php_error.log I find also a warning that says:
PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp64/bin/php/php5.6.25/ext/php_mongodb.dll' - Il sistema operativo non pu� eseguire %1.
in Unknown on line 0.
(for not Italian speaking, the phrase after - means the operating system can't execute %1, even if I can't imagine what %1 stands for).
Even using the new class MongoDB\Driver\Manager I get the error
Fatal error: Class 'MongoDB\Driver\Manager' not found in C:\wamp64\www\galileo\index.php on line 21
and the same warning.
Do you notice some error or forgetfulness in the installation process as I described and, if not, do you know how to fix the problem?
The problem is certainly related to WAMP and I think is related to the multiple php.ini in his folders. In fact, in the apache folder you can find a php.ini file that cannot be modified, otherwise nothing works at all; at the same time any changes made to the php.ini file in the php folder seems have no effect except making appear the mongodb extension in the extensions list.
So, I try using XAMPP, as suggested in this video tutorial and it works. Using Composer I was able to install also the PHP library and not only the driver.
you should not use 'MongoClient class' anymore, this extension that defines this class is deprecated. look at here.
instead, you should use MongoDB\Driver\Manager class. please read http://php.net/manual/en/class.mongodb-driver-manager.php.
and the setup must be like this in php:
$mongo = new MongoDB\Driver\Manager("mongodb://localhost:27017");
And if you still use the old class; you either need to install the old legacy extension (pecl install mongo) and use PHP 5.x, or update your code to use this new driver's classes as the old driver is not available for PHP 7. There is an upgrade guide at here.
the last part is from derickr's answer in this issue on github: https://github.com/mongodb/mongo-php-driver/issues/300

Class "String" not found error in PayPal core sdk

I am getting the following error all of sudden
Fatal error: Class 'string' not found in
\vendor\paypal\sdk-core-php\lib\PayPal\Common\PPModel.php on line 51
Did anything change in recent Wordpress update?
Around March, 2015, PayPal made some big
changes with PHP-SDK 1.0.0
Part of that change was renaming some classes;
PPModel.php was changed to PayPalModel.php
There were a lot of other files renamed.
Here is a link to all the breaking changes.
https://github.com/paypal/PayPal-PHP-SDK/wiki/Breaking-Changes---1.0.0
You will probably have a lot more work to do, other than just
PPModel. I know I had
to change 23 files and 73 lines of code. This is
because a lot of class files were renamed.
Well, I'm not sure why it's started happening to you right now, but I can see the bug:
the line mentioned initialises a class based on some reflected parameters
the reflection helper it calls defaults to returning "string", which isn't a valid class name
A couple of old closed bugs (#7, #34) mention Zend Optimizer, which is now known as OpCache, which could well be your culprit - it has a pair of settings opcache.save_comments and opcache.load_comments which must be set to On to save docblocks (/** ... */ comments) in memory. Since the Annotations relied on by the SDK are in such docblocks, if you've installed OpCache, or changed the value of that setting, your application will break.

cron kohana 3.3 wrong parametr in cli

I am getting this error
Parameter Errors:
uri - uri is not a valid option for this task!
but my command looks valid:
php /var/www/public_html/index.php --uri=controller/action
i tried also (direct in this folder)
php index.php --uri=controller/action
php index.php --uri="controller/action"
always this error
greetings
Kohana 3.3 changed the way it handles CLI execution. From 3.3 it uses Minion module and --uri param is dropped in favour of --task, therefore you have to create Tasks (as opposed to Controllers).
More in the docs: http://kohanaframework.org/3.3/guide/minion/tasks
Note that docs have an error, there's no $_defaults any more, there's $_options instead. Have a look into API Docs for more details.

Sonar and PHPMD: how to exclude directories

I'm trying Sonar and i've got some issues with it for a php project.
I have to do it multi-module to get at least php and js analysis.
this is my sonar-project.properties:
sonar.projectKey=xxxx
sonar.projectName=xxxx
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=
sonar.language=php
sonar.exclusions=htdocs/libraries/externals/**
sonar.phpCodesniffer.skip=true
sonar.modules=php-module,js-module
# PHP module
php-module.sonar.projectName=PHP Module
php-module.sonar.language=php
php-module.sonar.sources=
php-module.sonar.projectBaseDir=htdocs
php-module.sonar.exclusions=libraries/externals/**
# JavaScript module
js-module.sonar.projectName=JavaScript Module
js-module.sonar.language=js
js-module.sonar.sources=js
js-module.sonar.projectBaseDir=htdocs
But when i run sonar-runner, i get this error:
Exception in thread "main" org.sonar.runner.RunnerException: org.sonar.api.utils.SonarException: PHPMD execution failed with returned code '1'. Please check the documentation of PHPMD to know more about this failure
and the PHPMD error is
The parser has reached an invalid state near line "32" in file "/var/www/vhosts/dev3.xxxx.local/htdocs/libraries/externals/AvaTax4PHP/classes/ATConfig.class.php". Please check the following conditions: The keyword "parent" was used as type hint but the class "ATConfig" does not declare a parent.
But why is that happening if i've excluded the dir libraries in the project and the module?
Do i have to specify to PHPMD another list of exclusions?
For PHPMD (just as for PHP CodeSniffer, for example) you will have to specify a separate exclude pattern. You can use PHPMD's --excludeparameter for that.
Took me a while to figure it out, but you can set PHPMD's command line parameters with the following setting in your sonar-project.properties file:
sonar.phpPmd.argumentLine=--exclude libraries/externals
You can refer to this FAQ entry to know how to achieve your goal: http://docs.codehaus.org/display/SONAR/PHP+Plugin+FAQ#PHPPluginFAQ-HowdoIpreventexternaltoolsfromanalyzingsomesourcefiles
BTW, you should declare:
php-module.sonar.sources=.
, instead of:
php-module.sonar.sources=

Symfony2 vendors install

I'm trying to setup and create new bundle with symfony2, but getting so much error almost every step.
I'm download symfony and run this command;
php bin/vendors install
> Installing/Updating swiftmailer
Cloning into /var/www/Symfony/vendor/swiftmailer...
...
...
...
[ErrorException]
Warning: constant(): Couldn't find constant Monolog\Logger::iNFO in /var/www/Symfony/vendor/symfony/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php line 103
what is the problem? what should I do?
Error reason is Turkish system language. so in Turkish language "i" upper case "İ" and "I" lowercase "ı". I'm change my system language to English and problem solved.
write handler level uppercased to bypass this code
strtoupper($handler['level']))
for example
level: INFO
This sounds very very strange. The MonologExtension uses constant() at one point, and it does it like that:
constant('Monolog\Logger::'.strtoupper($handler['level']))
So basically, it uppercases the given level. Seeing the exception about ::iNFO not being found does not make sense, unless perhaps you have the mbstring extension enabled with the mbstring.func_overload option enabled as well.
Can you check if ini_get('mbstring.func_overload') returns 0/null? Otherwise that may be the cause. I really can't think of anything else.

Categories