April 5, 2013
No Comments
There is a problem in Magento that when you try to move a category by dragging it in the admin, it can cause the above error, whilst causing the rest of the site to slow down.
This is caused by the system trying to re-index every product within the space of a transaction.
An easy way to get round this is to switch the indexing mode from auto to manual and then move the categories.
You will still need to re-index the site, but this can be run on a cron when the site is quite.
February 20, 2013
No Comments
Sometime a backup script can go wrong, and rather the overwrite the old files you place a copy of the new ones into the same folder.
This can then escalate and before you know it you have multiple levels of the same files.
If you just want to flatten these files then this script can do that you
// The duplicated directory
DUPLICATED_DIR_NAME='uploads'
// A new directory for the files to go into
NEW_DIR_NAME='realuploads'
for f in <code>find ./ | grep $DUPLICATED_DIR_NAME/$DUPLICATED_DIR_NAME </code>;
do
NEWFILE=<code>echo $f | sed 's/$DUPLICATED_DIR_NAME\//\//g'</code>;
NEWDIR=../$NEW_DIR_NAME/<code>dirname $NEWFILE</code>;
if [[ ! -d $NEWDIR ]]
then
mkdir $NEWDIR;
fi
cp -f "$f" ../$NEW_DIR_NAME/$NEWFILE;
done
February 13, 2013
No Comments
Sometimes Magento will some times return no results with the message “Your search returns no results” for terms that you would expect it to return many results for.
This can happen for a number of reasons including misconfiguration of search or attributes.
Unfortunately the way Magento speeds up search queries suffers from a race condition that can lead Magento to think it has cached a query when it has not and at the same time believes there are no products for that search because the cache for that query was dropped. This is a tough issue to solve but it can be done.
The two methods that work effectively to resolve the race condition problem (thus far) are to first make sure that the query cache isn’t empty before using the cached results. This works effectively because if the cache is empty it must have been dropped recently and has not been repopulated.
The other thing you can do to help reduce this further is to make Magento remembers the time at which it dropped. Then have the query caches compare their last updated time against the the last cache drop time and if the update time is before or the same as the drop time don’t use the cache.
If this isn’t completely effective it is also possible to make it not use the query cache if the time of update and the time of drop are with in a minuet of each other to help reduce this further.
February 12, 2013
No Comments
I have recently been running some MySql scripts that wrote to a file.
These worked fine locally, but as soon as I deployed them I started to get the error above.
After much looking around I came across this solution.
When I was developing locally, I was connecting with a user that had global privileges. When I was running the code on the server I was connecting with a user that only had privileges for the database I was using.
The issue is that then FILE privilege is a Global setting, so the user did not have access to it, hence the access denied message.
Grant FILE privileges and you can connect as expected
January 24, 2013
No Comments
If you are struggling using PHPStorm to find and replace code with Regex rules then this is your solution.
The problem is that when using the $ sign in your replacement string it confuses it because PHP Storm uses the $ sign to represent sub pattern replacements.
Take the following example code:
$data = array();
$form=$page->find('form.edit_product', 0);
//standard inputs
$inputs = $form->find('input[type="text"]');
foreach($inputs as $input){
$data[$input->name]=$input->value;
}
//radio inputs
$inputs = $form->find('input[type="radio"]');
foreach($inputs as $input){
if($input->checked){
$data[$input->name]=$input->value;
}
}
//checkbox inputs
$inputs = $form->find('input[type="checkbox"]');
foreach($inputs as $input){
if($input->checked){
$data[$input->name]=$input->value;
}
}
//textareas
$textareas = $form->find('textarea');
foreach($textareas as $textarea){
$data[$textarea->name]=$textarea->innertext;
}
And trying to replace the key being used in the data array with a processed one calling a method $this-dataName($key) to generate the following code:
$data = array();
$form=$page->find('form.edit_product', 0);
//standard inputs
$inputs = $form->find('input[type="text"]');
foreach($inputs as $input){
$data[$this->dataName($input->name)]=$input->value;
}
//radio inputs
$inputs = $form->find('input[type="radio"]');
foreach($inputs as $input){
if($input->checked){
$data[$this->dataName($input->name)]=$input->value;
}
}
//checkbox inputs
$inputs = $form->find('input[type="checkbox"]');
foreach($inputs as $input){
if($input->checked){
$data[$this->dataName($input->name)]=$input->value;
}
}
//textareas
$textareas = $form->find('textarea');
foreach($textareas as $textarea){
$data[$this->dataName($textarea->name)]=$textarea->innertext;
}
You might try the find pattern:
\$data\[\$([^-]+)->name\]
And the replace pattern:
\$data\[\$this->dataName(\$$1->name)\]
However this will give you the dreaded “malformed replacement string” Error
The solution is simply to triple escape your dollar signs, so the replacement pattern becomes:
\\\$data\[\\\$this->dataName(\\\$$1->name\)\]
And it works, woot!
Also when it does work, PHP Storms replacement preview feature is really quite nice
phpstorm, By:
Joseph Edmonds
No Comments
Tags:
coding,
expressions,
find,
ide,
malformed,
php,
phpstorm,
problem,
regex,
regular,
replace,
replacement,
search,
solution,
string
January 15, 2013
No Comments
Recently I setup a machine with Linux Mint.
One of the things that was I needed to install was an up to date version of Sun Java. However, for various reasons, this no longer appears in the official repos.
Thankfully there is a different repo available here http://www.duinsoft.nl/packages.php?t=en where you can download the latest version and ensure that it is updated
January 11, 2013
No Comments
If you have a form designed to handle file uploads which is failing due to file size then you might like this:
$arrayMaxes = array(
'upload_max_filesize' => intval(ini_get('upload_max_filesize')),
'post_max_size' => intval(ini_get('post_max_size')),
'memory_limit' => intval(ini_get('memory_limit'))
);
$maxUploadSize = min($arrayMaxes);
foreach ($arrayMaxes as $key => $value) {
if ($value == min($arrayMaxes)) {
$minimumOfThree = $key;
break;
}
}
echo "The maximum file size you can upload is $maxUploadSize, this is due to the php.ini setting $mininimumOfThree";
This will calculate the smallest value that will be allowed based upon php.ini settings.
You can then incorporate this into your form logic and display so that users have a clear understanding of how large a file they can upload.
php, By:
Joseph Edmonds
No Comments
Tags:
file,
form,
html,
ini,
limit,
min,
php,
problem,
settings,
size,
upload
January 9, 2013
No Comments
I recently needed to trigger a couple of bash scripts through a web browser.
Unfortunately PHP shell_exec function grinds to a halt when it is used to trigger a long running / memory intensive script when it is used with Apache.
To get round this I instead wrote the command to a file and then wanted to trigger it using cron.
However, the commands that were being issues included a redirect and disown which were not being triggered in the following script
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
COMMAND=<code>cat ${DIR}/commandFile | tail -n 1</code>;
#Check the command
echo ${COMMAND};
# Command is /path/to/file.sh arg1 > /path/to/outputFile & disown
#Run the command
${TEST}
After having a play around I found that modifying the file to this will redirect the output and then disown the process
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
COMMAND=<code>cat ${DIR}/commandFile | tail -n 1</code>;
#Check the command
echo ${COMMAND};
# Command is /path/to/file.sh arg1 > /path/to/outputFile & disown
#Run the command - This line has been changed
eval ${TEST}
December 17, 2012
No Comments
When you’re uploading multiple files (HTML5 feature – remember IE as yet STILL does not support this), it may not be the fact you’re uploading multiple files that’s actually causing the problem.
The problem often is actually caused by the various php memory limits in play, one way to avoid getting caught by this is using the following snippet in the form’s php to remind you which restrictions are in play (note the min_by_key() function is from the php.net comments) :-
<?php
function min_by_key($arr, $key){
$min = array();
foreach ($arr as $val) {
if (!isset($val[$key]) and is_array($val)) {
$min2 = min_by_key($val, $key);
$min[$min2] = 1;
} elseif (!isset($val[$key]) and !is_array($val)) {
return false;
} elseif (isset($val[$key])) {
$min[$val[$key]] = 1;
}
}
return min( array_keys($min) );
}
$arrayMaxes = array(
'upload_max_filesize'=>intval(ini_get('upload_max_filesize')),
'post_max_size'=>intval(ini_get('post_max_size')),
'memory_limit'=>intval(ini_get('memory_limit'))
);
$maxUploadSize = min($arrayMaxes);
foreach ($arrayMaxes as $key=>$value) {
if ($value == min($arrayMaxes)) {
$minimumOfThree = $key;
}
}?>
<p>Max filesize <?php echo $maxUploadSize; ?>M Maximum filesize due to server setting <?php echo $minimumOfThree; ?> in php.ini</p>
December 12, 2012
5 Comments
I upgrade my laptop to the latest release of Linux Mint 14 MATE edition. Everything is working beautifully apart from the wireless which, whilst functional, was cripplingly slow.
After a load of searching and testing, the solution that worked for me was:
sudo -s
iwconfig wlan0 rate 54M
echo "options ath9k nohwcrypt=1" > /etc/modprobe.d/ath9k.conf
reboot
If you copy and paste the above into a terminal it will force the wifi speed to 54M and will make sure hardware crypt is disabled and finally reboot your machine.
I did this and my wifi speed is now perfectly fast, I’m a happy bunny
linux, By:
Joseph Edmonds
5 Comments
Tags:
,
12.10,
ath9k,
ifconfig,
issue,
linux,
mint,
nohwcrypt,
problem,
slow,
solution,
ubuntu,
wifi,
wireless,
wlan0