forked from Ortus-Solutions/ContentBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.cfc
242 lines (220 loc) · 8.65 KB
/
Application.cfc
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/**
* ContentBox - A Modular Content Platform
* Copyright since 2012 by Ortus Solutions, Corp
* www.ortussolutions.com/products/contentbox
* ---
* ContentBox Application Bootstrap
*/
component {
/**
* --------------------------------------------------------------------------
* NON COMMANDBOX INSTALLS
* --------------------------------------------------------------------------
* If you are NOT using CommandBox as your server, then set the variable to true
* and ContentBox will load the `.env` environment file defined by cbEnvFile.
*
* MAKE SURE THIS FILE IS NOT WEB ACCESSIBLE!
* Without this, your NON CommandBox ContentBox install will fail.
*/
this.cbLoadDynamicEnvironment = false;
this.cbEnvFile = expandPath( "/.env" );
if ( this.cbLoadDynamicEnvironment ) {
loadEnv();
}
/**
* --------------------------------------------------------------------------
* Application Properties: Modify as you see fit!
* --------------------------------------------------------------------------
*/
this.name = "ContentBox CMS";
this.sessionManagement = true;
this.sessionTimeout = createTimespan( 0, 1, 0, 0 );
this.setClientCookies = true;
this.setDomainCookies = true;
this.scriptProtect = false;
this.secureJSON = false;
this.timezone = "UTC";
/**
* --------------------------------------------------------------------------
* Lucee Specific Settings
* --------------------------------------------------------------------------
*/
// buffer the output of a tag/function body to output in case of a exception
this.bufferOutput = true;
// Activate Gzip Compression
this.compression = false;
// Turn on/off white space management
this.whiteSpaceManagement = "smart";
// Turn on/off remote cfc content whitespace
this.suppressRemoteComponentContent = false;
/**
* --------------------------------------------------------------------------
* ColdBox Bootstrap Settings
* --------------------------------------------------------------------------
* Modify only if you need to, else default them.
*/
COLDBOX_APP_ROOT_PATH = getDirectoryFromPath( getCurrentTemplatePath() );
COLDBOX_APP_MAPPING = "";
COLDBOX_WEB_MAPPING = "";
COLDBOX_CONFIG_FILE = "";
COLDBOX_APP_KEY = "";
COLDBOX_FAIL_FAST = true;
/**
* --------------------------------------------------------------------------
* Location Mappings
* --------------------------------------------------------------------------
* - cbApp : Quick reference to this application root
* - coldbox : Where ColdBox is installed
* - contentbox : Where the ContentBox module root is installed
* - cborm : Where the cborm library is installed: Needed for ORM Event Handling.
*/
this.mappings[ "/cbapp" ] = COLDBOX_APP_ROOT_PATH;
this.mappings[ "/coldbox" ] = COLDBOX_APP_ROOT_PATH & "coldbox";
this.mappings[ "/contentbox" ] = COLDBOX_APP_ROOT_PATH & "modules/contentbox";
this.mappings[ "/cborm" ] = this.mappings[ "/contentbox" ] & "/modules/contentbox-deps/modules/cborm";
/**
* --------------------------------------------------------------------------
* ORM + Datasource Settings
* --------------------------------------------------------------------------
* - Please update the cfcLocation as needed to locate more ORM entities for your app
* - Dialect is incredibly important! Do not let Hibernate auto configur it, you can get nasty errors.
* So Make sure you select one.
*/
request.cbSystemHelper = new coldbox.system.core.delegates.Env();
// THE CONTENTBOX DATASOURCE NAME
this.datasource = "contentbox";
// ORM SETTINGS
this.ormEnabled = true;
// cfformat-ignore-start
this.ormSettings = {
// ENTITY LOCATIONS, ADD MORE LOCATIONS AS YOU SEE FIT
cfclocation : [
// If you create your own app entities
"models",
// The ContentBox Core Entities
"modules/contentbox/models",
// Custom Module Entities
"modules_app",
// Custom Module User Entities
"modules/contentbox/modules_user"
],
// THE DIALECT OF YOUR DATABASE OR LET HIBERNATE FIGURE IT OUT, UP TO YOU TO CONFIGURE.
dialect : request.cbSystemHelper.getSystemSetting( "ORM_DIALECT", "" ),
dbcreate : "none",
secondarycacheenabled: request.cbSystemHelper.getSystemSetting( "ORM_SECONDARY_CACHE", false ),
cacheprovider : request.cbSystemHelper.getSystemSetting( "ORM_SECONDARY_CACHE", "ehCache" ),
logSQL : request.cbSystemHelper.getSystemSetting( "ORM_LOGSQL", false ),
sqlScript : request.cbSystemHelper.getSystemSetting( "ORM_SQL_SCRIPT", "" ),
// ORM SESSION MANAGEMENT SETTINGS, DO NOT CHANGE
flushAtRequestEnd : false,
autoManageSession : false,
// ORM EVENTS MUST BE TURNED ON FOR CONTENTBOX TO WORK DO NOT CHANGE
eventHandling : true,
eventHandler : "cborm.models.EventHandler",
// THIS IS ADDED SO OTHER CFML ENGINES CAN WORK WITH CONTENTBOX
skipCFCWithError : true,
// TURN ON FOR Debugging if ORM mappings are not working.
savemapping : false
};
// cfformat-ignore-end
// applicationStop();abort;
/*****************************************************************************************************/
/************************************** CF APP LISTENERS *********************************************/
/*****************************************************************************************************/
boolean function onApplicationStart(){
setting requestTimeout ="300";
application.cbBootstrap= new coldbox.system.Bootstrap(
COLDBOX_CONFIG_FILE,
COLDBOX_APP_ROOT_PATH,
COLDBOX_APP_KEY,
COLDBOX_APP_MAPPING,
COLDBOX_FAIL_FAST,
COLDBOX_WEB_MAPPING
);
application.cbBootstrap.loadColdbox();
return true;
}
boolean function onRequestStart( string targetPage ){
// In case bootstrap or controller are missing, perform a manual restart
if (
isNull( application.cbBootstrap )
||
isNull( application.cbController )
) {
if ( this.cbLoadDynamicEnvironment ) {
loadEnv( force: true );
}
reinitApplication();
}
// Development Reinit + ORM Reloads
if (
!isNull( application.cbController )
&&
application.cbController.getSetting( "environment" ) == "development"
&&
application.cbBootstrap.isFWReinit()
) {
if ( this.cbLoadDynamicEnvironment ) {
loadEnv( force: true );
}
if ( structKeyExists( server, "lucee" ) ) {
pagePoolClear();
}
ormReload();
}
// Process ColdBox Request
application.cbBootstrap.onRequestStart( arguments.targetPage );
return true;
}
function onSessionStart(){
if ( !isNull( application.cbBootstrap ) ) {
application.cbBootStrap.onSessionStart();
}
}
function onSessionEnd( struct sessionScope, struct appScope ){
arguments.appScope.cbBootStrap.onSessionEnd( argumentCollection = arguments );
}
boolean function onMissingTemplate( template ){
return application.cbBootstrap.onMissingTemplate( argumentCollection = arguments );
}
function onApplicationEnd( struct appScope ){
arguments.appScope.cbBootstrap.onApplicationEnd( arguments.appScope );
}
/*****************************************************************************************************/
/************************************** APP HELPERS **************************************************/
/*****************************************************************************************************/
/**
* Application Reinitialization
**/
private void function reinitApplication(){
onApplicationStart();
}
/**
* This method is only called if you are in a NON CommandBox install to load the environment variables
*/
private void function loadEnv( boolean force = false ){
var javaSystem = createObject( "java", "java.lang.System" );
var value = javaSystem.getProperty( "contentbox_runtime_env" );
// If not loaded, lock and load.
if ( isNull( value ) || arguments.force ) {
lock name="contentbox_runtime_env" timeout="15" throwOnTimeout="true" type="exclusive" {
// Double lock
if ( isNull( javaSystem.getProperty( "contentbox_runtime_env" ) ) || arguments.force ) {
// Load .env file
var props = createObject( "java", "java.util.Properties" ).init();
props.load( createObject( "java", "java.io.FileInputStream" ).init( this.cbEnvFile ) );
// Iterate and add
var availableProps = props.propertyNames();
while ( availableProps.hasNext() ) {
var propName = availableProps.next();
javaSystem.setProperty( propName, props.getProperty( propName ) );
}
javaSystem.setProperty( "contentbox_runtime_env", true );
}
// end double lock
}
// end lock
}
// end lock check
}
}