All about Magento E-commerce Store.......MagentoForum: Magento Connect Role Directories

Friday, September 16, 2011

Magento Connect Role Directories


This is less a full fledged article this time, and more "something I always forget and can never find anywhere else, so I'm posting it here to help future me".
When you're packaging up a Magento Extension for distribution through Magento Connect
System -> Magento Connect -> Package Extensions 
You need to create a list of Roles and Path pairs
The first time you do this, it's not entirely obvious what a Role or a Path is. If you expand the Role drop-down, you get a list of different file types.

Role defines (and labels) a certain sub-directory in your Magento install. The following Role/file-path pairs were valid for Magento 1.4.1.
  • Magento Local module file: ./app/code/local
  • Magento Community module file: ./app/code/community
  • Magento Core team module file: ./app/code/core
  • Magento User Interface (layouts, templates): ./app/design
  • Magento Global Configuration: ./app/etc
  • Magento PHP Library file: ./lib
  • Magento Locale language file: ./app/locale
  • Magento Media library: ./media
  • Magento Theme Skin (Images, CSS, JS): ./skin
  • Magento Other web accessible file: .
  • Magento PHPUnit test: ./tests
  • Magento other: .

Path defines a file path, from the base of the Role, to include in your packaged module.
Whenever I go to create a new Connect package, I always have to glop through the code to figure out which sub-directory a Role corresponds to. The last tie this happened I hacked together the following script to grab and display that information.
File: roles.php (in the root magento directory)  /** * Jumps into PEAR files to figure out what paths the connect roles belong to * worked on the 1.4.1 release, and I almost guarantee it'll break in a future * release.   */   function main() {     $paths  = get_key_path_pairs();     $labels     = get_labels();     render_labels_paths($paths, $labels); }     function render_labels_paths($paths, $labels) {     foreach($labels as $key=>$value)     {         echo $labels[$key] .          "\t:\t" .         $paths[$key] .         "\n";     } }  function load_roles() {     $inner = '';             foreach(glob('downloader/pearlib/php/PEAR/Installer/Role/*.xml') as $file)     {         $inner .= file_get_contents($file);      }     $xml = '<roles>'.$inner.'</roles>';     return simplexml_load_string($xml);  }  function get_key_path_pairs() {     $pairs = array();     foreach(load_roles() as $role)     {         $location_config = (string) $role->locationconfig;                   if($role->config_vars->{$location_config}->type &&          $role->config_vars->{$location_config}->type == 'directory')         {             $path = (string) $role->config_vars->{$location_config}->default;             $pairs[$location_config] = $path;         }     }     return $pairs;   }  function get_pair_roles() {     set_include_path('downloader/pearlib/php');     require('downloader/pearlib/php/PEAR/Command/Mage.php');     $fake       = null;     $command    = new PEAR_Command_Mage($fake,$fake);     return $command->getRoles(); }  function get_labels() {     $labels = array();     foreach(get_pair_roles() as $option=>$info)     {         if(array_key_exists('name', $info))         {             $labels[$info['dir_config']] = $info['name'];         }     }     return $labels; }  main();

No comments:

Post a Comment