1: <?php namespace Laravella\Crud;
2:
3: use Laravella\Crud\Log;
4: use \Seeder;
5: use \DB;
6:
7: class UpdateReferences extends CrudSeeder {
8:
9: 10: 11: 12: 13: 14:
15: public function run()
16: {
17: try
18: {
19:
20:
21:
22: DB::table('_db_key_fields')->delete();
23:
24: $this->updateReference('_db_fields', 'table_id', '_db_tables', 'id', 'name');
25: $this->updateReference('_db_fields', 'display_type_id', '_db_display_types', 'id', 'name');
26: $this->updateReference('_db_fields', 'widget_type_id', '_db_widget_types', 'id', 'name');
27:
28: $this->updateReference('_db_pages', 'view_id', '_db_views', 'id', 'name');
29: $this->updateReference('_db_pages', 'table_id', '_db_tables', 'id', 'name');
30: $this->updateReference('_db_pages', 'action_id', '_db_actions', 'id', 'name');
31:
32: $this->updateReference('users', 'usergroup_id', 'usergroups', 'id', 'group');
33:
34: $this->updateReference('_db_user_permissions', 'user_id', 'users', 'id', 'username');
35: $this->updateReference('_db_user_permissions', 'table_id', '_db_tables', 'id', 'name');
36: $this->updateReference('_db_user_permissions', 'action_id', '_db_actions', 'id', 'name');
37:
38:
39: $this->updateReference('_db_usergroup_permissions', 'table_id', '_db_tables', 'id', 'name');
40: $this->updateReference('_db_usergroup_permissions', 'action_id', '_db_actions', 'id', 'name');
41:
42: $this->updateReference('_db_menus', 'parent_id', '_db_menus', 'id', 'label');
43:
44: $this->updateReference('_db_menu_permissions', 'menu_id', '_db_menus', 'id', 'label');
45: $this->updateReference('_db_menu_permissions', 'usergroup_id', 'usergroups', 'id', 'group');
46:
47: $this->updateReference('medias', 'gallery_id', 'galleries', 'id', 'name');
48: $this->updateReference('medias', 'mcollection_id', 'mcollections', 'id', 'name');
49: $this->updateReference('medias', 'user_id', 'users', 'id', 'username');
50:
51: $this->updateReference('galleries', 'media_id', 'medias', 'id', 'file_name');
52:
53: $this->updateReference('_db_options', 'option_type_id', '_db_option_types', 'id', 'name');
54: $this->updateReference('_db_option_types', 'parent_id', '_db_option_types', 'id', 'name');
55:
56: $this->updateReference('_db_key_fields', 'pk_field_id', '_db_fields', 'id', 'fullname');
57: $this->updateReference('_db_key_fields', 'pk_display_field_id', '_db_fields', 'id', 'fullname');
58: $this->updateReference('_db_key_fields', 'fk_field_id', '_db_fields', 'id', 'fullname');
59: $this->updateReference('_db_key_fields', 'fk_display_field_id', '_db_fields', 'id', 'fullname');
60: $this->updateReference('_db_key_fields', 'key_type_id', '_db_key_types', 'id', 'name');
61:
62:
63:
64:
65: $this->updateReference('_db_key_fields', 'key_id', '_db_keys', 'id', 'name');
66: $this->updateReference('_db_keys', 'key_type_id', '_db_key_types', 'id', 'name');
67:
68: $this->updateReference('contents', 'content_type_id', 'content_types', 'id', 'name');
69:
70: $this->updateReference('_db_page_assets', 'page_type_id', '_db_option_types', 'id', 'name');
71: $this->updateReference('_db_page_assets', 'asset_type_id', '_db_assets', 'id', 'url');
72:
73: Log::write("success", "Completed foreign key references");
74: }
75: catch (Exception $e)
76: {
77: Log::write("success", "Error while inserting foreign key references.");
78: Log::write("success", $e->getMessage());
79: throw new Exception($e);
80: }
81: }
82:
83: }
84:
85: ?>
86: