воскресенье, 25 декабря 2011 г.

PHP sessions across sub domains

Params:
PHP-5.3, Apache-2.2

Problem:
I need a single session for mysite.com and admin.mysite.com domains. I would login on main domain mysite.com, and will be already authorized on sub domains like admin.mysite.com.


Solution:
In script before session start need too setup this session parameters:
session.cookie_path = "/"
session.cookie_domain = ".mysite.com" - dot at the beginning is important, it specify use same sessions on sub domains

Example:
Example for Zend Framework application.


Define site domain name value:
*** public/index.php ***
...
defined('SITE_DOMAIN_NAME')
|| define('SITE_DOMAIN_NAME', (getenv('SITE_DOMAIN_NAME') ? getenv('SITE_DOMAIN_NAME') : 'mysite.com'));
...
It seems, if server value SITE_DOMAIN_NAME is not defined, craete it. We will use it in config file.

You can define SITE_DOMAIN_NAME in .htaccess file, Anyway he need to be configured on every server separately.

*** public/.htaccess ***
...
SetEnv SITE_DOMAIN_NAME mysite.com
...

Further I set session values in config file
*** application/configs/application.ini ***
[production]
...
local.session.cookie_path = "/"
local.session.cookie_domain = "." SITE_DOMAIN_NAME
...
This line  "." SITE_DOMAIN_NAME  is equal to ".mysite.com"

And in Bootstrap.php wee initialize session.
*** application/Bootstrap.php ***
...
protected function _initSession()
{
$localCfg = new Zend_Config($this->getOption('local'), true);
Zend_Session::setOptions($localCfg->session->toArray());
Zend_Session::start();
}
...

пятница, 23 декабря 2011 г.

Zend Framework, bind subdomains to modules

Params:
Zend Framework 1.11, PHP-5.3, Apache 2.2, local pc with Gentoo on board.

Problem:
I want to bind subdomains to certain module of Zend Framework application.
Example: 
http://mysite.com - follow to default module of my app.
http://admin.mysite.com - follow to admin module.
Controllers, actions and params may be various(global variables also):
http://admin.mysite.com/index/index/foo/bar/......
etc.

Solution:
1) Create site with default Zend Framework module structure.
/var/www/mysite.com/
   application/
      configs/
      modules/
         admin/
            controllers/
            views/
         default/
            ......
      Bootstrap.php
   ......

2) Bind DocumentRoot folder of mysite.com, www.mysite.com, admin.mysite.com to the same folder. In my case it's:
/var/www/mysite.com/public

3) In Bootstrap.php file init application router:
 protected function _initRouter()
{
$router = Zend_Controller_Front::getInstance()->getRouter();
$hostnameDefaultRoute = new Zend_Controller_Router_Route_Hostname(':module.mysite.com'  , array('module' => 'default'));
$router->addRoute('default', $hostnameDefaultRoute->chain(new Zend_Controller_Router_Route(':lang/:controller/:action/*', array('lang' => 'en', 'controller'=>'index', 'action'=>'index'))));
  $hostnameDefaultRoute = new Zend_Controller_Router_Route_Hostname('mysite.com'  , array('module' => 'default'));
$router->addRoute('www', $hostnameDefaultRoute->chain(new Zend_Controller_Router_Route(':lang/:controller/:action/*', array('lang' => 'ru', 'controller'=>'index', 'action'=>'index'))))
->addRoute('login'  , $hostnameDefaultRoute->chain(new Zend_Controller_Router_Route_Static('login',   array('controller' => 'user', 'action'=>'login'))));
// routes for admin area
$hostnameAdminRoute = new Zend_Controller_Router_Route_Hostname('admin.mysite.com', array('module' => 'admin'));
$router->addRoute('admin' , $hostnameAdminRoute->chain(new Zend_Controller_Router_Route(':lang/:controller/:action/*',   array('lang' => 'en', 'controller'=>'index', 'action'=>'index'))))
->addRoute('settings' , $hostnameAdminRoute->chain(new Zend_Controller_Router_Route_Static('settings', array('controller' => 'config', 'action' => 'list'))));
}
==================================================================
In a result will work this url's:
mysite.com/ -> Module: default, IndexController, indexAction, lang: en
mysite.com/en/index/index -> Module: default, IndexController, indexAction, lang: en
mysite.com/en/index/index/foo/bar -> Module: default, IndexController, indexAction, lang: en , params: foo = bar
mysite.com/login -> Module: default, UserController, loginAction
admin.mysite.com -> Module: admin, indexController, indexAction, lang: en
admin.mysite.com/en/ -> Module: admin, indexController, indexAction, lang: en
admin.mysite.com/settings -> Module: admin, configController, listAction

4) Also you can use route names in view helper URL. In view script:
echo $this->url(array(), 'www') will output 'mysite.com/en/index/index'
echo $this->url(array('foo' => 'bar'), 'www') will output 'mysite.com/en/index/index/foo/bar'
echo $this->url(array(), 'login') will output 'mysite.com/login'
echo $this->url(array('page' => 1), 'admin') will output 'admin.mysite.com/en/index/index/page/1'
echo $this->url(array(), 'settings') will output 'admin.mysite.com/settings'
Also you can specify controllers and actions
echo $this->url(array('controller' => 'post', 'action' => 'list'), 'www') will output 'mysite.com/en/post/list'
echo $this->url(array('action' => 'print', 'id' => 2), 'admin') will output 'admin.mysite.com/en/index/print/id/2'

воскресенье, 18 декабря 2011 г.

Magento, change emails count in newsletter queue

Params:
Magento 1.6.0

Problem:
When cron execute newsletters, the count of emails which will be send is limited to 20 per request.

Solution:
Notice: This is bad solution!
Edit script app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php
Find string :
$countOfSubscritions = 20;
and set the value which you need. For me is "8" - limit of my hosting (emails count per request).

четверг, 15 декабря 2011 г.

Gentoo emerge: "A file is not listed in the Manifest ..."

Params:

Linux moon 2.6.39-gentoo-r3 #4 SMP Wed Aug 31 17:44:51 EEST 2011 i686 AMD Athlon(tm) XP 2000+ AuthenticAMD GNU/Linux

Problem:
When I do emerge <some_package> or upgrade my gentoo, emerge give me bulk of messages like this:
!!! A file is not listed in the Manifest '<package_ebuild>'
also have this warning:
Digest verification failed ...

Solution:
1) Download latest-portage snapshot from some gentoo mirrors:
    > cd /
    > wget ftp://gentoo.kiev.ua/snapshots/portage-20111214.tar.xz
2) Move /usr/portage directory for backup purposes:
     > mkdir /root/temp
     > mv /usr/portage /root/temp/
3) Extracting the portage snapshot:
    > tar xvjf /portage-20111214.tar.xz -C /usr
    > rm /portage-20111214.tar.xz
4) Sync new portage:
    > emerge --sync

That's all now you can update the system or .....
I don't know if this is correct solution, but it working for me.

воскресенье, 4 декабря 2011 г.

Where Magentoconnect manager save downloaded packages

Params:
Magento 1.6.0

Problem:
I have installed some package from magentoconnect, and I want to look inside this package.

Solution:
It saved here:
<path_to_magento_store_folder>/downloader/.cache/community/<package_name>.tgz