Monday, April 8, 2013

PHPStorm - Supporting Factory methods in Magento

I'm pleased to present a new feature in new PhpStorm 6.0.1 EAP build 129.177/196 which supports generic Factory Method pattern.

How to use

So, all is ok but how to generate file .phpstorm.meta.php? We have good tool n98-magerun which can generate our needed file for Magento in the environment of PHPStorm.
So all we need that this command with expected result:

# php n98-magerun.phar dev:ide:phpstorm:meta
Generating definitions for blocks group
Generating definitions for helpers group
Generating definitions for models group
Generating definitions for resource helpers group
Generating definitions for resource models group
File .phpstorm.meta.php generated


That's all. Your IDE is supporting Magento Factory methods now. Also, in theory, this feature works for other libraries.

Thursday, December 6, 2012

FreeBSD - Upgrade PHP version. Trouble with install pkgconf-0.8.9 from pkg-config-0.25_1

I got an error when try update PHP from 5.3.6 to latest 5.3.x.
===> Installing for pkgconf-0.8.9

 ===> pkgconf-0.8.9 conflicts with installed package(s):
 pkg-config-0.25_1

 They install files into the same place.
 Please remove them first with pkg_delete(1).
 *** Error code 1

 Stop in /usr/ports/devel/pkgconf.
 *** Error code 1

 Stop in /usr/ports/lang/php5.

In previous time I updated ports.
So, it happens because port got some updates which you can see in /usr/ports/UPDATING
It say:
AFFECTS: users of devel/pkg-config
  AUTHOR: bapt@FreeBSD.org

  devel/pkg-config has been replaced by devel/pkgconf

  # portmaster -o devel/pkgconf devel/pkg-config
  or
  # portupgrade -fo devel/pkgconf pkg-config-\*

  pkgng:
  # pkg set -o devel/pkg-config:devel/pkgconf
  # pkg install -f devel/pkgconf
I chose portmaster -o devel/pkgconf devel/pkg-config and updated relation. Further it try to install PHP again.

I found this solution from forum.

Friday, November 23, 2012

Git - Get all short hashes in line by filter. Add custom command to Git

Get all short hashes in line by filter

On work we have to add all hashes of Git revisions into an appropriate task. We wrote in the commit comments code of task and title:

Fixed PROJECT1-1245: Bug on the product page in the product price
- Fixed bug in the price calculation
- Updated tests


When I did many commits I have to copy each hash and paste to ticket.
73b7468,97fdcc7,60914f6,439bd39,e32ff69,199aa4

It's not dificult but we are programmers! :) So, I throught that it would be good to write a little script which will do this one.
#!/bin/sh
# Get all hashes by filtering of commit comment
if [ "$1" != "" ]; then
    OUT=$(git log --pretty=format:'%h' --reverse --grep $@)
    OUT=$(echo -e $OUT) #del line break
    echo ${OUT// /","}
else
    echo "Please set filter string as first parameter."
    exit
fi

Call to script in Git bash:

$ ~/get_hash.sh PROJECT1-1245
73b7468,97fdcc7,60914f6,439bd39,e32ff69,199aa46


Also you can add any Git parameters:

$ ~/get_hash.sh PROJECT1-1245 -3
439bd39,e32ff69,199aa46


Add custom command to Git

Let's make it as Git functional. :) I gave to this command name allhash. So we have to copy this file to
C:\Program Files (x86)\Git\libexec\git-core (on Windows 64)
with new filename by mask git-newcommandname. Our file have to get name git-allhash.
Let's call out new command:

$ git allhash PROJECT1-1245
73b7468,97fdcc7,60914f6,439bd39,e32ff69,199aa46

$ git allhash PROJECT1-1245 -3
439bd39,e32ff69,199aa46

Monday, August 13, 2012

PHPUnit - Error installing package of PHPUnit (Windows)

When I have install one package of PHPUnit under Windows I got error message:
No releases available for package "pear.phpunit.de/PHPUnit_Selenium"
install failed


I found error message in file /PEAR/REST/13.php this message and look PEAR_Error object.

[message] => SECURITY ERROR: Will not write to C:\Users\kirby\AppData\Local\Temp\pear\cache\972ec004d6044accd5359e2e011b92cerest.cacheid as it is symlinked to C:\Users\kirby\AppData\Local\Temp\pear\cache\972ec004d6044accd5359e2e011b92cerest.cacheid - Possible symlink attack


NOTE: Plz, go to %TMP% OR %TEMP% for find yours TEMP directory.

In truth, I did not found any simlinks. I chose simple solution: remove all cache files.
You can do it or manually or via command (recommended):
pear clear-cache

Wednesday, May 30, 2012

Magento - Position of validate message

Once I had a problem with position of the validate message "This is a required field." which should be close of hidden field. I need to add validation to some block, but it was from outside the parent blocks of input element. I was looking for how it work, and found simple solution: parent block should has CSS class «field-row».

<span class="field-row">
<input class="required-entry" id="some_id" type="hidden" />
</span>

Wednesday, May 23, 2012

Magento - error on recover data from backup

When I made backup of Magento (v1.5) and recover data from this backup then I got following error:

Magento: Recoverable Error: Argument 1 passed to Mage_Core_Model_Store::setWebsite() must be an instance of Mage_Core_Model_Website


I found solution (on this page):

SET FOREIGN_KEY_CHECKS=0;
UPDATE `core_store` SET store_id = 0 WHERE code='admin';
UPDATE `core_store_group` SET group_id = 0 WHERE name='Default';
UPDATE `core_website` SET website_id = 0 WHERE code='admin';
UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;

Tuesday, April 3, 2012

Magento - How to add new field type into Varien_Data_Form

Happens so that in the admin panel when we create new forms then it is necessary to add some element to the form Varien_Data_Form. Following example will shows how it can be done.

<?php
class My_Module_Block_Adminhtml_Product_Edit_Tab_Types extends Mage_Adminhtml_Block_Widget_Form
{
    //...

    /**
     * Prepare form
     *
     * @return Mage_Adminhtml_Block_Widget_Form
     */
    public function _prepareForm()
    {
        $form = new Varien_Data_Form();
        $this->setForm($form);
        $fieldset = $form->addFieldset('base_fieldset', array());

        $fieldset->addType('my_type',
            Mage::getConfig()->getBlockClassName('myModule/adminhtml_renderer_myType'));

        $fieldset->addField('my_type', 'label', array(
            'name'      => 'name_my_type',
            'label'     => $this->__('My Type'),
            'value'     => 'default value',
            'value_class'   => 'my-type-css-class',
        ));
        parent::_prepareForm();
        return $this;
    }

    //...
}

Next step we need to create necessary render model.


<?php
class My_Module_Block_Adminhtml_Renderer_MyType extends Varien_Data_Form_Element_Abstract
{
    /**
     * Get Html output.
     *
     * @return string
     */
    public function getElementHtml()
    {
        //do something for make HTML output
        $toHtml = "<div>My Type</div>"
        return $toHtml;
    }
}

That's all.