forked from jordanlev/c5_boilerplate_crud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.php
48 lines (38 loc) · 1.81 KB
/
controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
class BoilerplateCrudPackage extends Package {
protected $pkgHandle = 'boilerplate_crud';
protected $pkgName = 'Boilerplate CRUD';
protected $pkgDescription = 'Custom Dashboard Management - Boilerplate CRUD Operations';
protected $appVersionRequired = '5.5';
protected $pkgVersion = '0.1';
public function install() {
$pkg = parent::install(); //this will automatically install our package-level db.xml schema for us (among other things)
//Install seed data
$this->install_data($pkg->getPackagePath() . '/seed_data/categories.sql');
$this->install_data($pkg->getPackagePath() . '/seed_data/widgets.sql');
//Install dashboard pages
Loader::model('single_page');
$sp = SinglePage::add('/dashboard/boilerplate_crud', $pkg);
$sp->update(array('cName' => 'Boilerplate CRUD', 'cDescription' => 'Manage Sample Data for Boilerplate CRUD'));
//NOTE: Do not install single_pages for the various sub-pages of the main controller,
// because we will implement those as actions on the main controller instead
// (and if we installed separate single_pages, C5 would then look for separate controller
// files for each one -- instead of looking for the action method name in our one top-level controller).
}
private function install_data($sql_file) {
$db = Loader::db();
$sql = file_get_contents($sql_file);
$r = $db->execute($sql);
if (!$r) {
throw new Exception(t('Unable to install seed data: %s', $db->ErrorMsg()));
}
}
public function uninstall() {
parent::uninstall();
//Manually remove database tables (C5 unfortunately doesn't do this automatically via db.xml)
$db = Loader::db();
$sql = 'DROP TABLE BoilerplateCrudWidgets, BoilerplateCrudCategories';
$db->Execute($sql);
}
}