hubzero / hubzero-cms

Platform for Scientific Collaboration
https://hubzero.org
GNU General Public License v2.0
46 stars 57 forks source link

500 when moving "com_courses" from "core" to "app" #1640

Closed toanhminh0412 closed 1 year ago

toanhminh0412 commented 1 year ago

Bug Description

Moving com_courses from core to app produces a 500 error

Reproducibility

Starting with the HubZero code given with the VM, paste and app overlay code over the starting code. Simply move com_courses from core to app. It will produce a 500 error "Cannot redeclare class Components\Courses\Tables\Role" when accessing /courses.

For bugs with fixers: How was the code fixed? No fixes so far

Environment

Question Answer
HUBzero version 2.2.25
PHP version 5.6.40
OS & version CentOS Linux 7, comes with downloading HubZero VM

Additional Context (optional)

When I tried to move com_courses from core to app, I get an PHP 500 error: "Cannot redeclare class Components\Courses\Tables\Role"

toanhminh0412 commented 1 year ago

I found a fix for this: After migrating the app folder from core to app, the first 3 require_once lines of /com_courses/models/gradepolicies.php are importing files from the core folder. Make sure to change these 3 to import from the app folder. Then the component should work as expected.

Here is what I have in my new file: Change from

require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'tables' . DS . 'grade.policies.php';
require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'offering.php';
require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'section.php';

to

require_once dirname(__DIR__) . DS . 'tables' . DS . 'grade.policies.php';
require_once dirname(__DIR__) . DS . 'models' . DS . 'offering.php';
require_once dirname(__DIR__) . DS . 'models' . DS . 'section.php';