class IPF_Legacy_ORM_App extends IPF_Application
{
- public function __construct()
+ private static $appModels = array();
+
+ public static function appModelList($app)
{
- parent::__construct();
+ if (!array_key_exists($app->getName(), self::$appModels)) {
+ $models = array();
+ try {
+ $it = new DirectoryIterator($app->getPath().DIRECTORY_SEPARATOR.'models');
+ foreach ($it as $file) {
+ $e = explode('.', $file->getFileName(), 2);
+ if (count($e) == 2 && $e[1] === 'php') {
+ $models[] = $e[0];
+ }
+ }
+ } catch (RuntimeException $e) {
+ // nothing to do
+ }
+
+ // reorder models according to a given option
+ if (method_exists($app, 'admin_models_order')) {
+ $ordered = $app->admin_models_order();
+ foreach ($ordered as $modelname) {
+ if (!in_array($modelname, $models))
+ throw new IPF_Exception_Panic("Model \"$modelname\" does not exist.");
+ }
+ $models = array_merge($ordered, array_diff($models, $ordered));
+ }
+
+ self::$appModels[$app->getName()] = $models;
+ }
+ return self::$appModels[$app->getName()];
}
public function commands()
$models = array();
foreach ($project->appList() as $app)
- $models = array_merge($models, $app->modelList());
+ $models = array_merge($models, IPF_Legacy_ORM_App::appModelList($app));
IPF_ORM::createTablesFromModels($models);
}
public static function generateSqlFromModels($app)
{
- $sql = IPF_ORM_Manager::connection()->export->exportSortedClassesSql($app->modelList(), false);
+ $sql = IPF_ORM_Manager::connection()->export->exportSortedClassesSql(IPF_Legacy_ORM_App::appModelList($app), false);
$build = '';
foreach ($sql as $query) {