FOSUserBundle – compatibility break

Well, four days ago Stof authored a braking-change in FOSUserBundle; after updating vendors, you may encounter errors like "an encoder is not configured for Your\User\Entity" exception. This is basically because "algorithm" field from User entity was wiped out, and moved to FOSAdvancedEncoderBundle.

If you've encountered this, you basically have two options:

1) stick to 1.1.0 branch of FOSUserBundle by modifying your deps:

[FOSUserBundle]
    git=git://github.com/FriendsOfSymfony/FOSUserBundle.git
    target=bundles/FOS/UserBundle
    version=1.1.0

of course, if you don't want to ever upgrade to symfony 2.1 )

2) upgrade to master FOSUserBundle:

do

bin/vendors update

update doctrine schema (this will delete "algorithm" column):

app/console doctrine:schema:update --force

modify "encoders" section in security.yml:

 
  encoders:
    FOS\UserBundle\Model\UserInterface:
      algorithm: sha512
      encode_as_base64: false
      iterations: 1
 

encode_as_base64: false and iterations: 1 will add compatibility with you current encoded passwords from 1.1.0 version of FOSUserBundle.

Have fun!

Memcachedb & logs

Well, the memcachedb again ate whole sshd with infinite log.xxxxxxsomething files.

After a lot of digging around, found this memcachedb-guide-1.0. It appeared that memcachedb has db_archive command to purge all un-needed logs!

Just create a following file somewhere, e.g. /root/memcachedb_rotate_logs:

db_archive
quit

and add following to crontab to rotate memcachedb logs hourly:

0 * * * * /usr/bin/telnet localhost 21201 < /root/memcachedb_rotate_logs

(fix port number if needed).

Redmine rack initscript

Seems like the only normal way to run redmine is with rack

 
ruby script/server -e production
 

and this simple initscript:

 
#!/bin/bash
### BEGIN INIT INFO
# Provides:          redmine
# Required-Start:    $local_fs $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Redmine issue tracker
### END INIT INFO
 
case "$1" in
    start)
      cd /var/www/redmine/
      /usr/bin/ruby script/server -d -e production
    ;;
    stop)
      kill -9 `ps aux | grep "ruby script/server" | awk '{ print $2 }' | head -n 1`
    ;;
esac
 

mograil / passenger sucks beyond understanding

Direct links to controller without global routing rules in sf2

I suppose anyone is aware about path() twig function; it takes route name and returns URL. This is cool, but what if you use @Route annotation in Controller and need to link there without modifying routing.yml?

Here some magic comes in place - symfony internally generates name for each route imported via @Route annotation; the route is constructed in the following way:

(bundle name, converted to underscore, without 'bundle' suffix)
+ '_' +
(controller name, without 'controller' suffix, lowercase)
+ '_' +
(full controller method name, lowercase)

for example, if you have an Company\Hrm\GuiBundle, and some SimpleAuthController with method authorizeAction, like this:

 
/.../
class SimpleAuthController extends Controller
{
  /**
  * @Route("/auth")
  */
  public function authorizeAction()
  {
     /.../
  }
}
 

then

{{ path('company_hrm_gui_simpleauth_authorizeaction') }}

will return "/auth" link.

PS: And please, use it only for development and testing, this is a hardcode ;)

Setting PHPUnit for symfony projects on Ubuntu

Just a copy& paste guide:

 
#install pear, phpunit
sudo apt-get install php-pear phpunit
 
#upgrade pear - this is necessary
sudo pear upgrade PEAR
 
#install phpunit
sudo pear config-set auto_discover 1
sudo pear install pear.phpunit.de/PHPUnit
 

All done! Now you can run symfony tests:

 
cd vendor/symfony
php vendors.php
phpunit -c phpunit.xml.dist tests/
 

PHP wildcard matching function

Just published my PHP wildcard matching function on github - https://github.com/andrewtch/phpwildcard.

See doc there and use it like this:

 
wildcard_match('foo.*', 'foo.xy'); //true
wildcard_match('foo.?', 'foo'); //false
 

array wildcard matching is supported too:

 
wildcard_match('foo.*', array('boo.bar', 'foo.buz', 'buz.bar') // array('foo.buz')