Mike Purcell
(87 comments, 148 posts)
This user hasn't shared any profile information
Posts by Mike Purcell
PHPUnit – Upgrade – Convert assertType to assertInternalType
0We recently upgraded phpunit from a very old version to the current 3.6.x version (at time of writing). During the upgrade I noticed that assertType is no longer supported in many of our tests which were testing if something was a string, an array, or an object. So I had to write a quick script to update assertType to assertInternalType and figured I would post it for others if they needed to do the same.
$testsPath = '/path/to/your/tests';
$iter = new RecursiveDirectoryIterator($testsPath, FilesystemIterator::NEW_CURRENT_AND_KEY | FilesystemIterator::SKIP_DOTS);
foreach (new RecursiveIteratorIterator($iter) as $file) {
$extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
// Only want to deal with php scripts
if ($extension !== 'php') {
echo sprintf("Skipped: %s\n", $file->getRealPath());
continue;
}
echo sprintf("Parsing: %s\n", $file->getRealPath());
$contents = file($file->getRealPath());
foreach ($contents as &$content) {
if ((stripos($content, 'assertType') !== false) &&
((stripos($content, 'string') !== false) || (stripos($content, 'array') !== false)) || (stripos($content, 'float') !== false) || (stripos($content, 'object') !== false)) {
$content = str_ireplace('assertType', 'assertInternalType', $content);
}
}
file_put_contents($file->getRealPath(), $contents, LOCK_EX);
}
General – Introducing MeLikeDrinks.com
0Two and a half years ago I started writing a drink recipe search engine, which I would like to announce is finally ready for prime-time. The overall goal of the project was to provide a free-text drink recipe search engine that was easy to use and understand. During the time there were several similar sites but the UI/UX was terrible, so I thought to myself, “I can do better than that”. You can check out the drink recipe search engine @ MeLikeDrinks.com. Currently there are a few hundred drink recipes, but I am hoping to add many more over the next month.
MeLikeDrinks.com is the reason why I started MeLikeDev.com. I needed a way to save all the steps and configurations necessary to accomplish what needed to be done to support the website. For example, when learning Symfony I must have re-built the project (and model) a hundred times. Finally I got frustrated and wrote each step necessary and posted them to the blog, not only for myself, but anyone else who may be wandering down the same path.
Normally my projects don’t span years, but as any Symfonian knows, it is difficult to customize some Symfony “attributes” easily. For example, the “add a drink” form took longer than expected due to the complexity of nesting sub-forms, but also adding jquery interaction and custom validation. Plus the MeLikeDrinks.com project also resulted in a proprietary file-based storage engine currently code-named “Hobis”. Basically it stores pointers in xml format, which point to various file-system assets such as ingredient descriptions, and drink images. I am hoping to make Hobis open-source within the next year so others can take advantage of another nosql solution.
Thanks again for all the support over the years, and don’t forget to check out MeLikeDrinks.com and let me know what you think.
Magento – Reset Password – Your Password Reset Link has Expired – No Mail Server Access to Outside
0If you are working with Magento in a dev environment, it is a good chance that you don’t have an email server set which will access your @gmail.com email address. What I did to get around this is I would click the ‘forgot password’ link via Magento UI, then go into ‘/var/spool/mqueue’ where the email message is stored to be sent. I would then view the contents of the email to get the token needed to reset the password, and append it to the url so it looks like this: http://your.devenv.local/index.php/admin/index/resetpassword/?id=3D1&token=3Dfb17a3b930ae0699f003575461cb9542, but you need to be sure you remove the ’3D’ from the id and token params, otherwise the values are invalid. Once you do, you should be able to access the reset password form and reset your passwords.
Symfony – Doctrine – Call to a member function evictAll on a non-object
1If you are working with Symfony and Doctrine and encounter a “Call to a member function evictAll() on a non-object” error message, check to see if you are using DQL for any delete queries. I just came across this error and after some googling (mostly about bad schema files) I couldn’t fix the issue. I then checked a custom DQL statement which unlinks rows and saw that I had aliased the main table with ‘caa’, but the other references were ‘ca’ (only one a, instead of two). Once I fixed the alias issue, everything worked as expected.
General – Been awhile
0Sorry for the lack of updates over the last few weeks. I have been super busy getting a project ready for primetime. This weekend I am removing “beta” branding and will announce the project next week, so anyone interested can check it out. The project is reason why this blog was born as it incorporates numerous 3rd party vendors including Zend, Symfony, Lucene, CakePHP and others. So tune in next week for the post and thanks for all the support.
MySQL – Enable Query Logging
0Recently I wanted to track all the queries being executed for one of my applications, and found a great way to turn on query logging. I would then tail the log file and run through my app to see which queries were actually being executed. My app is based on doctrine (1.2) and I was amazed at how many queries were being executed, but I will save that for another article.
set global log_output = 'FILE'; set global general_log = 'ON'; set global general_log_file = '/var/log/mysql/queries.log';
Linux – CentOS – Install Mycrypt
0I have been working with Magento and came across another hurdle. Magento requires the mycrypt PHP module to be compiled, otherwise you will not be able to complete the install process. So naturally I opened up a terminal and typed `yum install mcrypt` only to find that no such libraries existed. Apparently, the default repos don’t provide the mcrypt libraries any more, so I had to use the EPEL repo, which does provide access to the required mcrypt libraries.
The following steps outline how I successfully installed mcrypt libraries on my CentOS (6.x) system:
Localize EPEL Repo
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
To verify that it was installed correctly, you can type `$ -> yum repolist`
Disable EPEL Repo
I don’t like not knowing what is installed on my system, as such I didn’t want to keep the EPEL repo enabled by default. Rather, I preferred to tell YUM to use EPEL only when I directed it to do so. In order to accomplish this, you need to make the following changes:
# /etc/yum.repos.d/epel.repo enabled=1 # to enabled=0
Now, the EPEL repo will not automatically be considered when you go to install a new package. Convenient for ensuring your system stays as “vanilla” as possible.
Install Mcrypt
$ -> yum install libmcrypt libmcrypt-devel mcrypt --enablerepo=epel
The libmcrypt-devel libraries are only necessary if you are going to install the PHP mcrypt module.
The above command will install the mcrypt libraries as provided by the EPEL repo.
Configure PHP
Now that we have mcrypt installed on our system, we can compile the PHP mcrypt module, first lets find out where mcrypt was installed:
$ -> which mcrypt /usr/bin/mcrypt
Now that we know where mcrypt is installed we can add the following flag to our PHP configure for compilation: –with-mcrypt=/usr/bin
After configure be sure to run make, and make install, after they are complete you should be able to `php -m` and see mcrypt as a compiled module.
Magento – Unable to Connect to Database
0Just spent 30 minutes fighting the magento GUI installer, which kept giving me a ‘unable to connect to database’ error. Only after trying a multitude of config permutations did I realize that I had to put a valid hostname (not localhost) into the hostname textbox (even though I could connect to localhost via command line). Before entering a hostname into the textbox, be sure the hostname is in accessible (either via DNS or /etc/hosts). Good luck.
General – Google New Privacy Policies Start Enforcement Today
0If you haven’t heard, Google will start enforcing their new privacy policies starting today (3.1.2012). From what I have read and heard, they are basically consolidating logging of usage of all of their services into one area. So if you have your web based gmail account open, and do a search through Google maps or Google search, they will be able to log this activity into one folder, representing you. It has been said that if you are not logged into any Google based services, that the best they can do is track your activity through your IP address. Also, it has been said that Google will “guess” the names of your contacts if you type a name into one of their services. For example, if you are typing in Google docs, the name of a contact and mis-spell their name, Google will attempt to auto-correct based off your contact list. Scary.
Personally, I don’t agree with these overly invasive privacy policies and will be looking to ways of abstracting my activities as much as possible, which includes; not using Google Chrome any more, switching from web based Gmail to IMAP client, and using a different search engine. It’s not that I have anything to hide, but this “big brother” approach in efforts of increasing revenues based off my activities has gone way past acceptable limits.
PHP – Magento – Zend – Missing Hash Function
0When it comes to manually configuring compiled applications on my systems, I am a minimalist, meaning that I always try to get away with the bare bones settings. Once in a great while this will come back to haunt me. In starting up a new project, I came across an issue where the Magento install process was throwing a fatal error regarding a ‘hash’ function (Zend Framework actually needed it). So I had to recompile with `–enable-hash` setting. Be sure to run a make clean before configure, otherwise your new setting won’t be picked up.
