]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/relationships/AbstractRelationships.php
Release 6.2.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / relationships / AbstractRelationships.php
1 <?php
2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3     die ( 'Not A Valid Entry Point' ) ;
4
5 /*********************************************************************************
6  * SugarCRM Community Edition is a customer relationship management program developed by
7  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
8  * 
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Affero General Public License version 3 as published by the
11  * Free Software Foundation with the addition of the following permission added
12  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
13  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
14  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15  * 
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
19  * details.
20  * 
21  * You should have received a copy of the GNU Affero General Public License along with
22  * this program; if not, see http://www.gnu.org/licenses or write to the Free
23  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24  * 02110-1301 USA.
25  * 
26  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
27  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28  * 
29  * The interactive user interfaces in modified source and object code versions
30  * of this program must display Appropriate Legal Notices, as required under
31  * Section 5 of the GNU Affero General Public License version 3.
32  * 
33  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
34  * these Appropriate Legal Notices must retain the display of the "Powered by
35  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
36  * technical reasons, the Appropriate Legal Notices must display the words
37  * "Powered by SugarCRM".
38  ********************************************************************************/
39
40
41 /*
42  * Abstract class for managing a set of Relationships
43  * The Relationships we're managing consist of metadata about relationships, rather than relationship implementations used by the application
44  * Relationships defined here are implemented by the build() method to become a relationship that the application can use
45  * Note that the modules/Relationships/Relationship.php contains some methods that look similar; remember though that the methods in that file are acting on implemented relationships, not the metadata that we deal with here
46  */
47 class AbstractRelationships
48 {
49     
50     static $methods = array ( 'Labels' => 'language' , 'RelationshipMetaData' => 'relationships' , 'SubpanelDefinitions' => 'layoutdefs' , 'Vardefs' => 'vardefs' , 'FieldsToLayouts' => 'layoutfields' ) ;
51     static $activities = array ( 'calls' => 'Calls' , 'meetings' => 'Meetings' , 'notes' => 'Notes' , 'tasks' => 'Tasks' , 'emails' => 'Emails' ) ;
52     
53     protected $relationships = array ( ) ; // array containing all the AbstractRelationship objects that are in this set of relationships
54     protected $moduleName ;
55     
56     /*
57      * Find all deployed modules that can participate in a relationship
58      * Return a list of modules with associated subpanels
59      * @param boolean $includeActivitiesSubmodules True if the list should include Calls, Meetings etc; false if they should be replaced by the parent, Activities
60      * @return array    Array of [$module][$subpanel]
61      */
62     static function findRelatableModules ($includeActivitiesSubmodules = true)
63     {
64         $relatableModules = array ( ) ;
65         
66         // add in activities automatically if required
67         $relatableModules [ 'Activities' ] [ 'default' ] = translate( 'LBL_DEFAULT' ) ;
68             
69         // find all deployed modules
70         require_once 'modules/ModuleBuilder/Module/StudioBrowser.php' ;
71         $browser = new StudioBrowser() ;
72         $browser->loadRelatableModules();
73         reset($browser->modules) ;
74
75         while ( list( $moduleName , $module ) = each($browser->modules) )
76         {
77             // do not include the submodules of Activities as already have the parent...
78             if (! $includeActivitiesSubmodules && in_array ( $module->module, self::$activities ))
79                 continue ;
80
81             $relatableModules [ $module->module ] = $module->getProvidedSubpanels() ;
82         }
83         
84         return $relatableModules ;
85     
86     }
87
88     static function validSubpanel ($filename)
89     {
90         if (! file_exists ( $filename ))
91             return false ;
92         
93         include $filename ;
94         return (isset ( $subpanel_layout ) && (isset ( $subpanel_layout [ 'top_buttons' ] ) && isset ( $subpanel_layout [ 'list_fields' ] ))) ;
95     }
96
97     /*
98      * Get a list of all relationships (which have not been deleted)
99      * @return array    Array of relationship names, ready for use in get()
100      */
101     function getRelationshipList ()
102     {
103         $list = array ( ) ;
104         foreach ( $this->relationships as $name => $relationship )
105         {
106             if (! $relationship->deleted ())
107                 $list [ $name ] = $name ;
108         }
109         return $list ;
110     }
111
112     /*
113      * Get a relationship by name
114      * @param string $relationshipName  The unique name for this relationship, as returned by $relationship->getName()
115      * @return AbstractRelationship or false if $relationshipName is not in this set of relationships
116      */
117     function get ($relationshipName)
118     {
119         if (isset ( $this->relationships [ $relationshipName ] ))
120         {
121             return $this->relationships [ $relationshipName ] ;
122         }
123         return false ;
124     }
125
126     /*
127      * Construct a relationship from the information in the $_REQUEST array
128      * If a relationship_name is provided, and that relationship is not read only, then modify the existing relationship, overriding the definition with any AbstractRelationship::$definitionkeys entries set in the $_REQUEST
129      * Otherwise, create and add a new relationship with the information in the $_REQUEST
130      * @return AbstractRelationship
131      */
132     function addFromPost ()
133     {
134         $definition = array ( ) ;
135         
136         require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationship.php' ;
137         foreach ( AbstractRelationship::$definitionKeys as $key )
138         {
139             if (! empty ( $_REQUEST [ $key ] ))
140             {
141                 $definition [ $key ] = ($key == 'relationship_type') ? AbstractRelationship::parseRelationshipType ( $_REQUEST [ $key ] ) : $_REQUEST [ $key ] ;
142             }
143         }
144         
145         // if this is a change to an existing relationship, and it is not readonly, then delete the old one
146         if (! empty ( $_REQUEST [ 'relationship_name' ] ))
147         {
148             if ($relationship = $this->get ( $_REQUEST [ 'relationship_name' ] ))
149             {
150                 unset( $definition[ 'relationship_name' ] ) ; // in case the related modules have changed; this name is probably no longer appropriate
151                 if (! $relationship->readonly ())
152                     $this->delete ( $_REQUEST [ 'relationship_name' ] ) ;
153         }
154         }
155         
156         $newRelationship = RelationshipFactory::newRelationship ( $definition ) ;
157         // TODO: error handling in case we get a badly formed definition and hence relationship
158         $this->add ( $newRelationship ) ;
159         return $newRelationship ;
160     }
161
162     /*
163      * Add a relationship to the set
164      * @param AbstractRelationship $relationship    The relationship to add
165      */
166     function add ($relationship)
167     {
168         $name = $this->getUniqueName ( $relationship ) ;
169         $relationship->setName ( $name ) ;
170         $this->relationships [ $name ] = $relationship ;
171     }
172
173     /*
174      * Load a set of relationships from a file
175      * The saved relationships are stored as AbstractRelationship objects, which isn't the same as the old MBRelationships definition
176      * @param string $basepath  Base directory in which to store the relationships information
177      * @return Array of AbstractRelationship objects
178      */
179     protected function _load ($basepath)
180     {
181         $GLOBALS [ 'log' ]->info ( get_class ( $this ) . ": loading relationships from " . $basepath . '/relationships.php' ) ;
182         $objects = array ( ) ;
183         if (file_exists ( $basepath . '/relationships.php' ))
184         {
185             include ($basepath . '/relationships.php') ;
186             foreach ( $relationships as $name => $definition )
187             {
188                 // update any pre-5.1 relationships to the new definitions
189                 // we do this here, rather than when upgrading from 5.0 to 5.1, as modules exported from MB in 5.0 may be loaded into 5.1 at any time
190                 // note also that since these definitions are only found in the relationships.php working file they only occur for deployed or exported modules, not published then loaded modules
191                 $definition = $this->_updateRelationshipDefinition( $definition ) ;
192                 $relationship = RelationshipFactory::newRelationship ( $definition ) ;
193                 // make sure it has a unique name
194                 if (! isset( $definition [ 'relationship_name' ] ) )
195                 {
196                     $name = $this->getUniqueName ( $relationship ) ;
197                     $relationship->setName ( $name ) ;
198                 }
199                 $objects [ $name ] = $relationship ;
200             }
201         }
202         return $objects ;
203     }
204
205     /*
206      * Save the set of relationships to a file
207      * @param string $basepath  Base directory in which to store the relationships information
208      */
209     protected function _save ($relationships , $basepath)
210     {
211         $GLOBALS [ 'log' ]->info ( get_class ( $this ) . ": saving relationships to " . $basepath . '/relationships.php' ) ;
212         $header = file_get_contents ( 'modules/ModuleBuilder/MB/header.php' ) ;
213         
214         $definitions = array ( ) ;
215         
216         foreach ( $relationships as $relationship )
217         {
218             // if (! $relationship->readonly ())
219             $definitions [ $relationship->getName () ] = $relationship->getDefinition () ;
220         }
221         
222         mkdir_recursive ( $basepath ) ;
223         // replace any existing relationships.php
224         write_array_to_file ( 'relationships', $definitions, $basepath . '/relationships.php', 'w', $header ) ;
225     }
226
227     /*
228      * Return all known deployed relationships
229      * All are set to read-only - the assumption for now is that we can't directly modify a deployed relationship
230      * However, if it was created through this AbstractRelationships class a modifiable version will be held in the relationships working file,
231      * and that one will override the readonly version in load()
232      *
233      * TODO: currently we ignore the value of the 'reverse' field in the relationships definition. This is safe to do as only one
234      * relationship (products-products) uses it (and there it makes no difference from our POV) and we don't use it when creating new ones
235      * @return array Array of $relationshipName => $relationshipDefinition as an array
236      */
237     protected function getDeployedRelationships ()
238     {
239         
240         $db = DBManagerFactory::getInstance () ;
241         $query = "SELECT * FROM relationships WHERE deleted = 0" ;
242         $result = $db->query ( $query ) ;
243         while ( $row = $db->fetchByAssoc ( $result ) )
244         {
245             // set this relationship to readonly
246             $row [ 'readonly' ] = true ;
247             $relationships [ $row [ 'relationship_name' ] ] = $row ;
248         }
249         
250         return $relationships ;
251     }
252
253     /*
254      * Get a name for this relationship that is unique across all of the relationships we are aware of
255      * We make the name unique by simply adding on a suffix until we achieve uniqueness
256      * @param AbstractRelationship The relationship object
257      * @return string A globally unique relationship name
258      */
259     protected function getUniqueName ($relationship)
260     {
261         $allRelationships = $this->getRelationshipList () ;
262         $basename = $relationship->getName () ;
263         
264         if (empty ( $basename ))
265         {
266             // start off with the proposed name being simply lhs_module_rhs_module
267             $definition = $relationship->getDefinition () ;
268             $basename = strtolower ( $definition [ 'lhs_module' ] . '_' . $definition [ 'rhs_module' ] ) ;
269         }
270         
271         $name = $basename ;
272         $suffix = 1 ;
273         while ( isset ( $allRelationships [ $name ] ) )
274         {
275             $name = $basename . "_" . ( string ) ($suffix ++) ;
276         }
277         return $name ;
278     }
279     
280     /*
281      * Translate the set of relationship objects into files that the Module Loader can work with
282      * @param string $basepath          Pathname of the directory to contain the build
283      * @param string $installDefPrefix  Pathname prefix for the installdefs, for example for ModuleBuilder use "<basepath>/SugarModules"
284      * @param array $relationships      Relationships to implement
285      */
286     protected function build ($basepath , $installDefPrefix , $relationships )
287     {
288         global $sugar_config;
289         // keep the relationships data separate from any other build data by ading /relationships to the basepath
290         $basepath .= '/relationships' ;
291
292         $installDefs = array ( ) ;
293         $compositeAdded = false ;
294         foreach ( self::$methods as $method => $key )
295         {
296             $buildMethod = 'build' . $method ;
297             $saveMethod = 'save' . $method ;
298             
299             foreach ( $relationships as $name => $relationship )
300             {
301                 if (! ($relationship->readonly () || $relationship->deleted ()))
302                 {
303                     if (method_exists ( $relationship, $buildMethod ) && method_exists ( $this, $saveMethod ))
304                     {
305                         $metadata = $relationship->$buildMethod () ;
306                         
307                         if (count ( $metadata ) > 0) // don't clutter up the filesystem with empty files...
308                         {
309                             $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . ": BUILD is running METHOD $saveMethod" ) ;
310                             $installDef = $this->$saveMethod ( $basepath, $installDefPrefix, $name, $metadata ) ;
311                             
312                             // some save methods (e.g., saveRelateFieldDefinition) handle the installDefs internally and so return null
313
314                         
315                             if (! is_null ( $installDef ))
316                             {
317                                 foreach ( $installDef as $moduleName => $def )
318                                 {
319                                     $installDefs [ $key ] [ ] = $def ;                                                                             
320                                 }
321                             }
322                         }
323                     }
324                 
325                 }
326             }
327         }
328         
329         return $installDefs ;
330     }
331
332     /*
333      * SAVE methods called during the build to translate the metadata provided by each relationship into files for the module installer
334      * Note that the installer expects only one file for each module in each section of the manifest - multiple files result in only the last one being implemented!
335      */
336     
337     /*
338      * Add a set of labels to the module
339      * @param string $basepath              Basepath location for this module
340      * @param $installDefPrefix             Pathname prefix for the installdefs, for example for ModuleBuilder use "<basepath>/SugarModules"
341      * @param string $relationshipName      Name of this relationship (for uniqueness)
342      * @param array $labelDefinitions       Array of System label => Display label pairs
343      * @return null Nothing to be added to the installdefs for an undeployed module
344      */
345     protected function saveLabels ($basepath , $installDefPrefix , $relationshipName , $labelDefinitions)
346     {
347         global $sugar_config;
348         
349         mkdir_recursive ( "$basepath/language" ) ;
350         
351         $headerString = "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n" ;
352         $installDefs = array ( ) ;
353         foreach ( $labelDefinitions as $definition )
354         {
355                 $mod_strings = array();
356                 $app_list_strings = array();
357                 
358                 $out = $headerString;
359                 
360                 $filename = "{$basepath}/language/{$definition['module']}.php" ;
361         
362                 if (file_exists ( $filename ))
363                         include ($filename);
364                         
365             
366             //Check for app strings
367             $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->saveLabels(): saving the following to {$filename}" 
368                                       . print_r ( $definition, true ) ) ;
369             if ($definition['module'] == 'application') {
370                 $app_list_strings[$definition [ 'system_label' ]] = $definition [ 'display_label' ];
371                 foreach ($app_list_strings as $key => $val)
372                         $out .= override_value_to_string_recursive2('app_list_strings', $key, $val);
373             } else {
374                 $mod_strings[ $definition [ 'system_label' ]] = $definition [ 'display_label' ];
375                 foreach ($mod_strings as $key => $val)
376                         $out .= override_value_to_string_recursive2('mod_strings', $key, $val);
377             }
378             
379             $fh = fopen ( $filename, 'w' ) ;
380             fputs ( $fh, $out, strlen ( $out ) ) ;
381             fclose ( $fh ) ;
382             
383                 
384             foreach($sugar_config['languages'] as $lk => $lv)
385             {
386                 $installDefs [ $definition [ 'module' ] . "_$lk" ] = array ( 
387                         'from' => "{$installDefPrefix}/relationships/language/{$definition [ 'module' ]}.php" , 
388                         'to_module' => $definition [ 'module' ] , 
389                         'language' => $lk 
390                 ) ;                                             
391             }
392             
393             /* do not use the following write_array_to_file method to write the label file - 
394              * module installer appends each of the label files together (as it does for all files) 
395                          * into a combined label file and so the last $mod_strings is the only one received by the application */
396                 // write_array_to_file ( 'mod_strings', array ( $definition [ 'system_label' ] => $definition [ 'display_label' ] ), $filename, "a" ) ;
397         }
398         
399         return $installDefs ;
400     }
401
402     /*
403      * Translate a set of relationship metadata definitions into files for the Module Loader
404      * @param string $basepath              Basepath location for this module
405      * @param $installDefPrefix             Pathname prefix for the installdefs, for example for ModuleBuilder use "<basepath>/SugarModules"
406      * @param string $relationshipName      Name of this relationship (for uniqueness)
407      * @param array $relationshipMetaData   Set of metadata definitions in the form $relationshipMetaData[$relationshipName]
408      * @return array $installDefs           Set of new installDefs
409      */
410     protected function saveRelationshipMetaData ($basepath , $installDefPrefix , $relationshipName , $relationshipMetaData)
411     {
412         mkdir_recursive ( "$basepath/relationships" ) ;
413         
414         $installDefs = array ( ) ;
415         list ( $rhs_module, $properties ) = each ( $relationshipMetaData ) ;
416         $filename = "$basepath/relationships/{$relationshipName}MetaData.php" ;
417         $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->saveRelationshipMetaData(): saving the following to {$filename}" . print_r ( $properties, true ) ) ;
418         write_array_to_file ( 'dictionary["' . $relationshipName . '"]', $properties, "{$filename}", 'w' ) ;
419         $installDefs [ $relationshipName ] = array ( /*'module' => $rhs_module , 'module_vardefs' => "<basepath>/Vardefs/{$relationshipName}.php" ,*/ 'meta_data' => "{$installDefPrefix}/relationships/relationships/{$relationshipName}MetaData.php" ) ;
420         
421         return $installDefs ;
422     }
423
424     /*
425      * Translate a set of subpanelDefinitions into files for the Module Loader
426      * @param string $basepath              Basepath location for this module
427      * @param $installDefPrefix             Pathname prefix for the installdefs, for example for ModuleBuilder use "<basepath>/SugarModules"
428      * @param array $subpanelDefinitions    Set of subpanel definitions in the form $subpanelDefinitions[$for_module][]
429      * @return array $installDefs           Set of new installDefs
430      */
431     protected function saveSubpanelDefinitions ($basepath , $installDefPrefix , $relationshipName , $subpanelDefinitions)
432     {
433         mkdir_recursive ( "$basepath/layoutdefs/" ) ;
434         
435         foreach ( $subpanelDefinitions as $moduleName => $definitions )
436         {
437             $filename = "$basepath/layoutdefs/{$relationshipName}_{$moduleName}.php" ;
438             $out =  "<?php\n// created: " . date('Y-m-d H:i:s') . "\n";
439             foreach ( $definitions as $definition )
440             {
441                 $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->saveSubpanelDefinitions(): saving the following to {$filename}" . print_r ( $definition, true ) ) ;
442                 if (empty($definition ['get_subpanel_data']) || $definition ['subpanel_name'] == 'history' ||  $definition ['subpanel_name'] == 'activities') {
443                         $definition ['get_subpanel_data'] = $definition ['subpanel_name'];
444                 }
445                 $out .= '$layout_defs["' . $moduleName . '"]["subpanel_setup"]["' . $definition ['get_subpanel_data'] . '"] = ' 
446                       . var_export_helper($definition) . ";\n";
447             }
448             file_put_contents($filename, $out);
449             $installDefs [ $moduleName ] = array ( 'from' => "{$installDefPrefix}/relationships/layoutdefs/{$relationshipName}_{$moduleName}.php" , 'to_module' => $moduleName ) ;
450         }
451         return $installDefs ;
452     }
453
454     /*
455      * Translate a set of linkFieldDefinitions into files for the Module Loader
456      * Note that the Module Loader will only accept one entry in the vardef section of the Manifest for each module
457      * This means that we cannot simply build a file for each relationship as relationships that involve the same module will end up overwriting each other when installed
458      * So we have to append the vardefs for each relationship to a single file for each module
459      * @param string $basepath              Basepath location for this module
460      * @param $installDefPrefix             Pathname prefix for the installdefs, for example for ModuleBuilder use "<basepath>/SugarModules"
461      * @param string $relationshipName      Name of this relationship (for uniqueness)
462      * @param array $linkFieldDefinitions   Set of link field definitions in the form $linkFieldDefinitions[$for_module]
463      * @return array $installDefs           Set of new installDefs
464      */
465     protected function saveVardefs ($basepath , $installDefPrefix , $relationshipName , $vardefs)
466     {
467         mkdir_recursive ( "$basepath/vardefs/" ) ;
468         $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->saveVardefs(): vardefs =" . print_r ( $vardefs, true ) ) ;
469         
470         foreach ( $vardefs as $moduleName => $definitions )
471         {
472             // find this module's Object name - the object name, not the module name, is used as the key in the vardefs...
473             if (isset ( $GLOBALS [ 'beanList' ] [ $moduleName ] ))
474             {
475                 $module = get_module_info ( $moduleName ) ;
476                 $object = $module->object_name ;
477             } else
478             {
479                 $object = $moduleName ;
480             }
481             
482             $relName = $moduleName;
483             foreach ( $definitions as $definition )
484             {
485                 if (!empty($definition['relationship']))
486                 {
487                         $relName = $definition['relationship'];
488                         break;
489                 }
490             }
491             
492             $filename = "$basepath/vardefs/{$relName}_{$moduleName}.php" ;
493             
494             $out =  "<?php\n// created: " . date('Y-m-d H:i:s') . "\n";
495             foreach ( $definitions as $definition )
496             {
497                 $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->saveVardefs(): saving the following to {$filename}" . print_r ( $definition, true ) ) ;
498                 $out .= '$dictionary["' . $object . '"]["fields"]["' . $definition [ 'name' ] . '"] = '
499                           . var_export_helper($definition) . ";\n";
500             }
501             file_put_contents($filename, $out);
502             
503             $installDefs [ $moduleName ] = array ( 
504                 'from' => "{$installDefPrefix}/relationships/vardefs/{$relName}_{$moduleName}.php" , 
505                 'to_module' => $moduleName 
506             ) ;
507         }
508         
509         $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->saveVardefs(): installDefs =" . print_r ( $installDefs, true ) ) ;
510         
511         return $installDefs ;
512     
513     }
514
515     /*
516      * Determine if we're dealing with a deployed or undeployed module based on the name
517      * Undeployed modules are those known to ModuleBuilder; the twist is that the deployed names of modulebuilder modules are keyname_modulename not packagename_modulename
518      * and ModuleBuilder doesn't have any accessor methods based around keys, so we must convert keynames to packagenames
519      * @param $deployedName Name of the module in the deployed form - that is, keyname_modulename or modulename
520      * @return array ('moduleName'=>name, 'packageName'=>package) if undeployed, ('moduleName'=>name) if deployed
521      */
522     static function parseDeployedModuleName ($deployedName)
523     {
524         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php' ;
525         $mb = new ModuleBuilder ( ) ;
526         
527         $packageName = '' ;
528         $moduleName = $deployedName ;
529         
530         foreach ( $mb->getPackageList () as $name )
531         {
532             // convert the keyName into a packageName, needed for checking to see if this is really an undeployed module, or just a module with a _ in the name...
533             $package = $mb->getPackage ( $name ) ; // seem to need to call getPackage twice to get the key correctly... TODO: figure out why...
534             $key = $mb->getPackage ( $name )->key ;
535             if (strlen ( $key ) < strlen ( $deployedName ))
536             {
537                 $position = stripos ( $deployedName, $key ) ;
538                 $moduleName = trim( substr( $deployedName , strlen($key) ) , '_' ); //use trim rather than just assuming that _ is between packageName and moduleName in the deployedName
539                 if ( $position !== false && $position == 0 && (isset ( $mb->packages [ $name ]->modules [ $moduleName ] )))
540                 {
541                     $packageName = $name ;
542                     break ;
543                 }
544             }
545         }
546         
547         if (! empty ( $packageName ))
548         {
549             return array ( 'moduleName' => $moduleName , 'packageName' => $packageName ) ;
550         } else
551         {
552             return array ( 'moduleName' => $deployedName ) ;
553         }
554     }
555
556
557 }