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

PHP sessions across sub domains

PHP-5.3, Apache-2.2

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.

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 for Zend Framework application.

Define site domain name value:
*** public/index.php ***
|| 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 ***
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);

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

Zend Framework, bind subdomains to modules

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

I want to bind subdomains to certain module of Zend Framework application.
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):

1) Create site with default Zend Framework module structure.

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

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

Magento 1.6.0

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

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 ..."


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

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 ...

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

Magento 1.6.0

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

It saved here: