Sequence of rules - input

My application is not working correctly with my input parametres.
I have 2 rules at config urlManager:
'<controller:\w+>/<action:\w+>/<factor:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>/<factor:\w+>/<ids:((id\d+)|\d)+>'=>'<controller>/<action>'
At my action I try 2 inputs: id12id78 and 87(any number).
With the first input, the action gets id12id78, but if I try the second input, my $ids parameter is empty.
How I can fix the bug?

Well, nothing strange :
id12id78 : the second rule will be applied : $ids => id12id78
87 : the first rule will be applied : $id => 87
I don't think you need to different params here, you should use only id, e.g. :
'<controller:\w+>/<action:\w+>/<factor:\w+>/id<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>/<factor:\w+>/<id:\d+>'=>'<controller>/<action>',

Related

How do use fuzzy matching validation for either a non-present key or an empty array?

In karate version 0.9.6 I used the following match statement in a .feature file and it worked for validating the value to be an empty array or a key that was not present.
def example = {}
match example.errors == '##[0]'
In 1.0 the documentation example suggests that this should check for the key being present and null or an empty array and testing this fails with a validation error that the value is not present.
From https://karatelabs.github.io/karate/#schema-validation
# should be null or an array of strings
* match foo == '##[] #string'
This appears to be an undocumented breaking change from pre-1.0 to 1.0.
My question is: how do I construct a validator to cover this case correctly when the key is allowed to be absent but if it is present it must be an empty array?
I've found an undesirable solution for now but am leaving this open in case someone has a better answer.
I'm validating the entire parent object with a minimal schema:
Replace
match $.errors == '##[0]'
With
* match $ == { data: '#object', extensions: '##object', errors: '##[0]' }
While more brittle and verbose it is technically working.
This indeed looks like an in-intended breaking change. Here is another workaround:
* def example = {}
* def expected = example.errors ? '#[0]' : '#notpresent'
* match example.errors == expected
I see you have opened an issue here: https://github.com/karatelabs/karate/issues/1825
EDIT: this might be an improvement over the workaround you came up with in your answer:
* match example contains { errors: '##[0]' }

Prestashop and null fields in DB

I have a very simple piece of code :
$dropOrder = new DropOrder($dropOrderId);
$dropOrder->is_supplier_paid = $payValue;
$dropOrder->save();
It works and saves a 'is_supplier_paid' field value into the database. But it also does unexpected actions and fills all null valued fields with 0 values.
I try to save it like this :
$dropOrder->save(true);
But I still have the same strange behavior. I want to change one field only and don't touch the other ones.
Values are formated by ObjectModel::formatValue() before they are inserted / updated, based on the type of the field declared in your $definition.
You have to use TYPE_NOTHING to allow NULL values, it's the only way.
Take a look in Configuration class, with id_shop and id_group_shop fields.
PrestaShop 1.7:
I ran into the same problem in PS 1.7 and set TYPE_NOTHING is not sufficient to resolve this issue. In my case i also needed to add allow_null to true in the field's definition:
'my_field' => ['type' => self::TYPE_NOTHING, 'allow_null' => true, 'value' => null]
('value' => null is probably not necessary but suggested)

ANTLR: return always the same number of children

I have the following rule:
statement : TOKEN1 opt1=TOKEN2? opt2=TOKEN3 TOKEN4 -> ^(TOKEN1 opt1? opt2);
The AST generated by this rule will have one or two children (depending on if
opt1 was defined or not).
I need to have always a fixed number of children (in this case 2). I know that
this can be achieved by doing the following (UNDEFINED is an imaginary token):
statement : TOKEN1 opt1=TOKEN2 TOKEN4 -> ^(TOKEN1 opt1 UNDEFINED)
| TOKEN1 opt1=TOKEN2 opt2=TOKEN3 TOKEN4 -> ^(TOKEN1 opt1 opt2);
This is fine for just one optional token. The problem is when I have a higher
number of optional tokens. A lot of rules must written in order to catch all
possible combinations. How can this issue be solved in an elegant way?
I'm using ANTLR 3.4/C target by the way.
Thanks,
T.
You could do this:
grammar G;
tokens {
CHILD1;
CHILD2;
CHILD3;
}
...
statement
: ROOT t2=TOKEN2? t3=TOKEN3? t4=TOKEN4?
-> ^(ROOT ^(CHILD1 $t2?) ^(CHILD2 $t3?) ^(CHILD3 $t4?))
;
which will cause the AST to always have 3 child nodes (which may or may not have a tokens as child themselves).

Parameterized DeleteAllByAttributes Doesn't Work in YII

I am using the following code:
MyClass::model()->deleteAllByAttributes(array('phone_number'=>':phone_number'), '', array(':phone_number'=>$phoneNumber));
And I am getting the following error:
CDbException
SQLSTATE[HY093]: Invalid parameter number: number of bound variables
does not match number of tokens. The SQL statement executed was:
DELETE FROM `my_class` WHERE `my_class`.`phone_number`=:yp0
(E:\xampp\htdocs\yii\db\CDbCommand.php:354)
I believe you don't need to bind the attributes in the attributes array (as in findAllByAttributes() too). The values in the params array are bound to values in the condition string, not the attributes array, so I believe the following should work for you (and be sanitized):
MyClass::model()->deleteAllByAttributes(array(
'phone_number'=>$phoneNumber,
));
Alternatively, you could use:
MyClass::model()->deleteAllByAttributes(array(),'`phone_number` = :phone_number',array(
':phone_number'=>$phoneNumber,
));
Which would have the same effect... But then you might as well use deleteAll():
MyClass::model()->deleteAll('`phone_number` = :phone_number',array(
':phone_number'=>$phoneNumber,
));

Amazon API -- Can I search Category ALL - Other than DVD etc?

I Am trying to build play with API code from Amazon -- I am a noob at this --
I have created a product search using the simple lookup code, and have gone though and set the search field form a form submission works fine, how ever I don't want to set a category Like I am currently below to say DVD, BABY MUSIC, I wish to set to ALL is this possible?
include("amazon_api_class.php");
$obj = new AmazonProductAPI(); -- I have edited this and added ALL as a category in here
try
{
$result = $obj->searchProducts($query,
AmazonProductAPI::BABY, -- I can change this to DVD or MUSIC and it works but if i set to ALL i get errors?
"TITLE"); - tryed changing this to KEYWORD doesnt work!
}
catch(Exception $e)
Any Help Would Be nice.
Thanks
Carl
OK --- updated -- ANd I belive I have to use KEYWORD when USING ALL so I have added this in
case "KEYWORD" : $parameters = array("Operation" => "ItemSearch",
"Title" => $search,
"SearchIndex" => $category,
"ResponseGroup" => "Small",
"MerchantId" => "All",
"Condition"=>"New",
'Keywords' => $searchTerm);
Warning: Invalid argument supplied for foreach() in /data/ADMINwhere2shoponline/www/include/amazon.php on line 23
still get this error?
carl
Carl,
You should be able to use ALL as the search parameter, but you need to make sure that the number of ItemPage you are requesting is not more than 5 or it will return an error. All other categories allow up to 10, but ALL is limited to 5.
Check that and see if you yet your problem resolved.