2017-11-20 05:31 PST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000678v2.3 Release (Closed)[All Projects] Generalpublic2011-03-24 09:53
Reportereureka 
Assigned Tocaseydk 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
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

-Relationships
+Relationships

-Notes

~0001511

caseydk (administrator)

*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 (reporter)

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 (reporter)

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 (reporter)

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 (administrator)

Resolved in r1605
+Notes

-Issue History
Date Modified Username Field Change
2010-12-30 05:43 eureka New Issue
2010-12-30 06:06 caseydk Status new => assigned
2010-12-30 06:06 caseydk Assigned To => caseydk
2010-12-30 06:08 caseydk Note Added: 0001511
2010-12-30 11:28 eureka Note Added: 0001512
2010-12-30 11:42 eureka Note Added: 0001513
2010-12-30 11:50 eureka Note Added: 0001514
2011-01-23 22:59 caseydk Project v2.2 Release (Closed) => v2.3 Release (Closed)
2011-01-23 23:00 caseydk Note Added: 0001580
2011-01-23 23:00 caseydk Status assigned => resolved
2011-01-23 23:00 caseydk Resolution open => fixed
2011-03-24 09:53 caseydk Fixed in Version => 2.3
2011-03-24 09:53 caseydk Status resolved => closed
+Issue History