Import/export issues
acidtalks - July 5, 2009 - 11:09
| Project: | Custom filter |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
| Issue tags: | 6.x-1.0-beta3, 6.x-2.0-beta1 |
Description
When I try to export a newly created filter I get the following error message:
warning: preg_match_all() expects at least 3 parameters, 2 given in /Applications/xampp/xamppfiles/htdocs/drupal/sites/all/modules/customfilter/customfilter.export.inc on line 93.
The "Export data" textarea contains code but if I try to reimport this code another error occurs:
The import data is not valid import text.

#1
#2
May you report here the code that you see in the text area?
I have already resolved the issue caused by the wrong call to
preg_match_all(), which has been removed because not necessary; to understand if there is another issue I need to see the code reported in the text area.Thanks for your report.
#3
First, here is the code for a simple filter I have exported:
$filter = array(
'fid' => _customfilter_map_filter_id('4'),
'name' => base64_decode('RmlsdGVyICM0'),
'cache' => 1,
'description' => base64_decode(''),
'shorttips' => base64_decode(''),
'longtips' => base64_decode(''),
);
$rules[] = array(
'rid' => _customfilter_map_rule_id('5'),
'fid' => _customfilter_map_filter_id('4'),
'prid' => _customfilter_map_rule_id('0'),
'name' => base64_decode('JDE='),
'description' => base64_decode(''),
'matches' => base64_decode('MQ=='),
'pattern' => base64_decode('L3JlZ2V4L2k='),
'replacement' => base64_decode('UmVndWxhciBFeHByZXNzaW9ucw=='),
'code' => 0,
'weight' => 0,
);
The error message from line 93 occurs, because preg_match_all misses the $matches parameter. Here is a fix (see patch attached).
'#rows' => max(40, preg_match_all('/(\r\n?|\n)/', $export_data, $matches)),But this does not affect the generated export. It seems to be okay. The import fails, because the imported textarea is always empty. In customfilter.import.inc (line 29) the form parameter '#value' is set to an empty string. This should be '#default_value' (see patch).
If you have an empty database the import now works. But there is another problem if there are already some filters there. In this case the functions _customfilter_map_filter_id and _customfilter_map_rule_id don't work correct. I think because
if (isset($fids[$id])) {$fids[$id] = (integer) db_result(db_query("SELECT MAX(fid) FROM {customfilter_filters}")) + 1;
}
should have a NOT-Operator:
if (!isset($fids[$id])) {$fids[$id] = (integer) db_result(db_query("SELECT MAX(fid) FROM {customfilter_filters}")) + 1;
}
Then there is at least a problem with the 'prid'. I think it should not be mapped. In my case the prid was '0' before the export and '5' after the import. This leads to a filter without rules. Correcting this to '0' helped.
Maybe you can have a quick look at the patches.
#4
The first patch is not necessary. The way I used to calculate the number of rows was totally wrong; as I am saving the lines of code into an array, it's enough to count the number of items in the array, to know the number of code rows.
You are right; the IF-statement should verify if the array item is not already set, and set it in that case.
The prid field (which is the parent rule ID) needs to be mapped; only in the case it is 0 (which means "no parent rule") it should not mapped to a new value.
You are also right about "#value"; the code was meant to set "#default_value" ("#value" should never be set).
Thanks for the help given.
#5
I changed the code, and committed it in CVS.
As a rid cannot be equal to zero, I changed
_customfilter_map_rule_id()to simply return zero when the actual parameter it gets is zero.Thanks again for your help. If there is still something in the import/export code that needs to be changed, feel free to reopen this report.
#6
I was forgetting about the 6.x-1 branch that needs to be changed as well.
#7
#8
#9
Automatically closed -- issue fixed for 2 weeks with no activity.