MantisBT - v2.3 Release (Closed)
View Issue Details
0000678v2.3 Release (Closed)[All Projects] Generalpublic2010-12-30 05:432011-03-24 09:53
Reportereureka 
Assigned Tocaseydk 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version2.3 
Summary0000678: Autoload problem
DescriptionThe autoloader tries to load the main class of a module by first using the plural form of its name and on failure, use the singular form. To get there, it adds an "s" to the end of its name unless it ends with y, in which case it replaces it with "ies", then it removes the final 's'.

For company, it's ok:
1) company becomes Companies => find it

For holiday, it's not ok
1) holiday becomes holidaies => not found
2 holidaies becomes holidaie => not found
TagsNo tags attached.
Attached Files

Notes
(0001511)
caseydk   
2010-12-30 06:08   
*Blast* you just had to come up with an extra case that broke everything. ;)

In the shortterm, you can use the getModuleClass() to get that one.

What rule do you suggest for adding this one?
(0001512)
eureka   
2010-12-30 11:28   
My first suggestion :
in w2p_autoload (file main_functions.php) change "default" of switch statement by :

        default:
            if (file_exists(W2P_BASE_DIR.'/classes/'.$name.'.class.php')) {
                require_once W2P_BASE_DIR.'/classes/'.$name.'.class.php';
                return;
            }
            $q = new DBQuery;
            $q->addTable('modules');
            $q->addQuery('mod_directory');
            $q->addWhere("mod_main_class = '$class_name'");
            $name = $q->loadResult();
            if (! $name) {
              return;
            }
            if (file_exists(W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php')) {
                require_once W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php';
                return;
            }
            break;
(0001513)
eureka   
2010-12-30 11:42   
My second suggestion :
1) add the following function in main_functions.php :
function pluralize($word) {
    $rules= array(
    '/(matr|vert|ind)(ix|ex)$/i' => '\1ices', # matrix, vertex, index
    '/(ss|sh|ch|x|z)$/i' => '\1es', # sibilant rule (no ending e)
    '/([^aeiou])o$/i' => '\1oes', # -oes rule
    '/([^aeiou]|qu)y$/i' => '\1ies', # -ies rule
    '/sis$/i' => 'ses', # synopsis, diagnosis
    '/(m|l)ouse$/i' => '\1ice', # mouse, louse
    '/(t|i)um$/i' => '\1a', # datum, medium
    '/([li])fe?$/i' => '\1ves', # knife, life, shelf
    '/(octop|vir|syllab)us$/i' => '\1i', # octopus, virus, syllabus
    '/(ax|test)is$/i' => '\1es', # axis, testis
    '/([a-rt-z])$/i' => '\1s' # not ending in s
    );
    $irregulars = array(
    'bus' => 'busses',
    'child' => 'children',
    'man' => 'men',
    'person' => 'people',
    'quiz' => 'quizzes',
    'equipment' => 'equipment',
    'fish' => 'fish',
    'information' => 'information',
    'money' => 'money',
    'moose' => 'moose',
    'news' => 'news',
    'rice' => 'rice',
    'series' => 'series',
    'sheep' => 'sheep',
    'species' => 'species'
    );
    if (isset($irregulars[$word])) {
        return $irregulars[$word];
    }
  foreach ($rules as $regex => $replace) {
    $word = preg_replace($regex, $replace, $word, 1, $count);
    if ($count) {
      return $word;
    }
  }
  return $word;
}

2) change "default" of switch statement by :

        default:
            if (file_exists(W2P_BASE_DIR.'/classes/'.$name.'.class.php')) {
                require_once W2P_BASE_DIR.'/classes/'.$name.'.class.php';
                return;
            }

            if ($name[0] == 'c') {
                $name = substr($name, 1);
                if (file_exists(W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php')) {
                  require_once W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php';
                  return;
                }
                if (in_array($name, array('system'))) {
                    //do nothing
                } else {
                    $name = pluralize($name);
                }
            }
            
            if (file_exists(W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php')) {
                require_once W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php';
                return;
            }
            break;
(0001514)
eureka   
2010-12-30 11:50   
I tested the two suggested solutions, they work

The first one is more "natural" but there is an access to the database.
The second requires an additional function

I'll let you choose ...
(0001580)
caseydk   
2011-01-23 23:00   
Resolved in r1605

Issue History
2010-12-30 05:43eurekaNew Issue
2010-12-30 06:06caseydkStatusnew => assigned
2010-12-30 06:06caseydkAssigned To => caseydk
2010-12-30 06:08caseydkNote Added: 0001511
2010-12-30 11:28eurekaNote Added: 0001512
2010-12-30 11:42eurekaNote Added: 0001513
2010-12-30 11:50eurekaNote Added: 0001514
2011-01-23 22:59caseydkProjectv2.2 Release (Closed) => v2.3 Release (Closed)
2011-01-23 23:00caseydkNote Added: 0001580
2011-01-23 23:00caseydkStatusassigned => resolved
2011-01-23 23:00caseydkResolutionopen => fixed
2011-03-24 09:53caseydkFixed in Version => 2.3
2011-03-24 09:53caseydkStatusresolved => closed