Skip to content

Commit 04f5b0c

Browse files
committed
Fallback to admin app if sql file is missing in current app
1 parent 8024901 commit 04f5b0c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

system/core/startup.php

+23-5
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ function autoload($class) {
154154
$pluginName = strtolower(preg_replace('/(?<!^)(?<!\/)(?<!\\\)[A-Z]/', '-$0', $pluginName));
155155
$sqlFile = DIR_PLUGINS . $pluginName . 'sql' . DS . DB_ENGINE . DS . $file . '.sql';
156156
} else {
157-
$sqlFile = strtolower($sqlFile);
158-
$sqlFile = DIR_SQL . $sqlFile . '.sql';
157+
$sqlFile = strtolower($sqlFile) . '.sql';
158+
//$sqlFile = DIR_SQL . $sqlFile . '.sql';
159159
}
160160

161161
$name = str_replace(['\\', 'sql' . DS], [DS, ''], strtolower($relativeClass));
@@ -172,12 +172,30 @@ function autoload($class) {
172172
$fileExists = file_exists($file);
173173

174174
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) {
176194
throw new \Exception(sprintf(\Vvveb\__('SQL file %s does not exist for %s!'), $sqlFile, $relativeClass));
177195
}
178196
//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);
181199
$fileExists = true;
182200
}
183201
}

0 commit comments

Comments
 (0)