@@ -154,8 +154,8 @@ function autoload($class) {
154
154
$ pluginName = strtolower (preg_replace ('/(?<!^)(?<!\/)(?<! \\\)[A-Z]/ ' , '-$0 ' , $ pluginName ));
155
155
$ sqlFile = DIR_PLUGINS . $ pluginName . 'sql ' . DS . DB_ENGINE . DS . $ file . '.sql ' ;
156
156
} else {
157
- $ sqlFile = strtolower ($ sqlFile );
158
- $ sqlFile = DIR_SQL . $ sqlFile . '.sql ' ;
157
+ $ sqlFile = strtolower ($ sqlFile ) . ' .sql ' ;
158
+ // $sqlFile = DIR_SQL . $sqlFile . '.sql';
159
159
}
160
160
161
161
$ name = str_replace (['\\' , 'sql ' . DS ], [DS , '' ], strtolower ($ relativeClass ));
@@ -172,12 +172,30 @@ function autoload($class) {
172
172
$ fileExists = file_exists ($ file );
173
173
174
174
if (SQL_CHECK || ! $ fileExists ) {
175
- if (! file_exists ($ sqlFile )) {
175
+ $ sqlExists = false ;
176
+
177
+ if ($ isFromPlugin > 0 ) {
178
+ $ fullSqlFile = $ sqlFile ;
179
+ $ sqlExists = file_exists ($ fullSqlFile );
180
+ } else {
181
+ //fallback to admin if sql file is missing in APP
182
+ foreach ([APP , 'admin ' ] as $ app ) {
183
+ $ fullSqlFile = DIR_ROOT . $ app . DS . 'sql ' . DS . DB_ENGINE . DS . $ sqlFile ;
184
+
185
+ if (file_exists ($ fullSqlFile )) {
186
+ $ sqlExists = true ;
187
+
188
+ break ;
189
+ }
190
+ }
191
+ }
192
+
193
+ if (! $ sqlExists ) {
176
194
throw new \Exception (sprintf (\Vvveb \__ ('SQL file %s does not exist for %s! ' ), $ sqlFile , $ relativeClass ));
177
195
}
178
196
//if the file has not been generated yet or sql files is changed recompile
179
- if (! $ fileExists || ((filemtime ($ sqlFile ) > filemtime ($ file )))) {
180
- regenerateSQL ($ sqlFile , $ file , $ modelName , $ namespace );
197
+ if (! $ fileExists || ((filemtime ($ fullSqlFile ) > filemtime ($ file )))) {
198
+ regenerateSQL ($ fullSqlFile , $ file , $ modelName , $ namespace );
181
199
$ fileExists = true ;
182
200
}
183
201
}
0 commit comments