From: avl
Date: Fri, 29 Aug 2008 02:41:00 +0000 (+0200)
Subject: Import Scheme refactor
X-Git-Tag: 0.5~521
X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=704f120a14639067b9e2b9566256ff956e3d53c7;p=ipf.git
Import Scheme refactor
---
diff --git a/ipf/admin/models/_generated/BaseAdminLog.php b/ipf/admin/models/_generated/BaseAdminLog.php
index e7114fc..930e5eb 100644
--- a/ipf/admin/models/_generated/BaseAdminLog.php
+++ b/ipf/admin/models/_generated/BaseAdminLog.php
@@ -1,7 +1,7 @@
models)==0)
- // return;
IPF_ORM::generateModelsFromYaml($this->path.'models.yml', $this->path.'models');
}
diff --git a/ipf/auth/models/_generated/BasePermission.php b/ipf/auth/models/_generated/BasePermission.php
index 3813475..4be9891 100644
--- a/ipf/auth/models/_generated/BasePermission.php
+++ b/ipf/auth/models/_generated/BasePermission.php
@@ -1,7 +1,7 @@
loadModels();
print IPF_Project::getInstance()->generateSql();
}
diff --git a/ipf/form.php b/ipf/form.php
index 3ab6c0d..40d7518 100644
--- a/ipf/form.php
+++ b/ipf/form.php
@@ -194,14 +194,12 @@ class IPF_Form implements Iterator
public function render_p()
{
- return $this->htmlOutput('%1$s%2$s %3$s%4$s
', '%s', '
',
- ' %s', true);
+ return $this->htmlOutput('%1$s%2$s %3$s%4$s
', '%s', '', ' %s', true);
}
public function render_ul()
{
- return $this->htmlOutput('%1$s%2$s %3$s%4$s', '%s',
- '', ' %s', false);
+ return $this->htmlOutput('%1$s%2$s %3$s%4$s', '%s', '', ' %s', false);
}
public function render_table()
@@ -266,3 +264,4 @@ function IPF_Form_renderErrorsAsHTML($errors)
}
return '';
}
+
diff --git a/ipf/orm/import/builder.php b/ipf/orm/import/builder.php
index 34d683f..2b996af 100644
--- a/ipf/orm/import/builder.php
+++ b/ipf/orm/import/builder.php
@@ -14,7 +14,6 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder
protected $_baseClassName = 'IPF_ORM_Record';
protected $_generateAccessors = false;
protected static $_tpl;
-
public function __construct()
{
$this->loadTemplate();
@@ -66,6 +65,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder
if ($bool !== null) {
$this->_generateAccessors = $bool;
}
+
return $this->_generateAccessors;
}
@@ -127,7 +127,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder
}
self::$_tpl = '/**' . PHP_EOL
- . ' * This class has been auto-generated by the IPF ORM Framework' . PHP_EOL
+ . ' * This class has been auto-generated by the IPF_ORM Framework' . PHP_EOL
. ' */' . PHP_EOL
. '%sclass %s extends %s' . PHP_EOL
. '{'
@@ -289,6 +289,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder
if ($code) {
return ' public function setUp()' . PHP_EOL . ' {' . PHP_EOL . ' ' . $code . PHP_EOL . ' }';
}
+
}
public function buildColumns(array $columns)
@@ -312,13 +313,13 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder
unset($options['ntype']);
// Remove notnull => true if the column is primary
- // Primary columns are implied to be notnull in IPF
+ // Primary columns are implied to be notnull in IPF_ORM
if (isset($options['primary']) && $options['primary'] == true && (isset($options['notnull']) && $options['notnull'] == true)) {
unset($options['notnull']);
}
// Remove default if the value is 0 and the column is a primary key
- // IPF defaults to 0 if it is a primary key
+ // IPF_ORM defaults to 0 if it is a primary key
if (isset($options['primary']) && $options['primary'] == true && (isset($options['default']) && $options['default'] == 0)) {
unset($options['default']);
}
@@ -491,6 +492,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder
return PHP_EOL." ".'$this->addListener(new '.$listener.'());';
}
+
public function buildAttributes(array $attributes)
{
$build = PHP_EOL;
@@ -582,12 +584,10 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder
public function buildRecord(array $definition)
{
- if ( ! isset($definition['className'])) {
+ if ( !isset($definition['className'])) {
throw new IPF_ORM_Exception('Missing class name.');
}
-
$definition['topLevelClassName'] = $definition['className'];
-
if ($this->generateBaseClasses()) {
$definition['is_package'] = (isset($definition['package']) && $definition['package']) ? true:false;
@@ -702,7 +702,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder
$this->writeTableDefinition($definition['tableClassName'], $writePath, array('extends' => $definition['inheritance']['tableExtends']));
}
}
- // If it is the base class of the ipf record definition
+ // If it is the base class of the IPF_ORM record definition
else if (isset($definition['is_base_class']) && $definition['is_base_class']) {
// If it is a part of a package then we need to put it in a package subfolder
if (isset($definition['is_package']) && $definition['is_package']) {
diff --git a/ipf/orm/import/schema.php b/ipf/orm/import/schema.php
index b8c64aa..e44ac1c 100644
--- a/ipf/orm/import/schema.php
+++ b/ipf/orm/import/schema.php
@@ -72,12 +72,12 @@ class IPF_ORM_Import_Schema
'keyValue'));
protected $_validators = array();
+
public function getValidators()
{
if (empty($this->_validators)) {
$this->_validators = IPF_ORM_Utils::getValidators();
}
-
return $this->_validators;
}
@@ -142,12 +142,13 @@ class IPF_ORM_Import_Schema
$builder->setOptions($this->getOptions());
$array = $this->buildSchema($schema, $format);
-
+
foreach ($array as $name => $definition) {
+
if ( ! empty($models) && !in_array($definition['className'], $models)) {
continue;
}
- print " $name\n";
+ print " $name\n";
$builder->buildRecord($definition);
}
}
@@ -338,6 +339,8 @@ class IPF_ORM_Import_Schema
$moves = array('columns' => array());
foreach ($array as $className => $definition) {
+ if (!isset($definition['className']))
+ continue;
$parent = $this->_findBaseSuperClass($array, $definition['className']);
// Move any definitions on the schema to the parent
if (isset($definition['inheritance']['extends']) && isset($definition['inheritance']['type']) && ($definition['inheritance']['type'] == 'simple' || $definition['inheritance']['type'] == 'column_aggregation')) {
@@ -401,7 +404,7 @@ class IPF_ORM_Import_Schema
foreach ($relations as $alias => $relation) {
$class = isset($relation['class']) ? $relation['class']:$alias;
- if ( ! isset($array[$class])) {
+ if (!isset($array[$class])) {
continue;
}
$relation['class'] = $class;
@@ -444,6 +447,7 @@ class IPF_ORM_Import_Schema
// Make sure we do not have any duplicate relations
$this->_fixDuplicateRelations();
+ //$array['relations'];
// Set the full array of relationships for each class to the final array
foreach ($this->_relations as $className => $relations) {
$array[$className]['relations'] = $relations;
@@ -531,7 +535,6 @@ class IPF_ORM_Import_Schema
}
$validation = array_flip($validation);
-
foreach ($element as $key => $value) {
if ( ! isset($validation[$value])) {
throw new IPF_ORM_Exception(sprintf('Invalid schema element named "' . $value . '"
diff --git a/ipf/project.php b/ipf/project.php
index 932c290..0c8b38d 100644
--- a/ipf/project.php
+++ b/ipf/project.php
@@ -3,6 +3,7 @@
final class IPF_Project{
private $apps = array();
+ public $sqlProfiler = null;
static private $instance = NULL;
@@ -66,7 +67,7 @@ final class IPF_Project{
return $sql;
}
- private function loadModels(){
+ public function loadModels(){
foreach( $this->apps as $appname=>&$app){
$this->getApp($appname)->loadModels();
}
@@ -81,12 +82,18 @@ final class IPF_Project{
$dsn = IPF::get('dsn');
if ($dsn=='')
throw new IPF_Exception_Panic('Specify dsn in config file');
- IPF_ORM_Manager::connection($dsn);
- $this->loadModels();
+ $conn = IPF_ORM_Manager::connection($dsn);
+
+ if (IPF::get('debug')){
+ $this->sqlProfiler = new IPF_ORM_Connection_Profiler();
+ IPF_ORM_Manager::getInstance()->getCurrentConnection()->setListener($this->sqlProfiler);
+ }
+
if (php_sapi_name()=='cli'){
$this->cli();
return;
}
+ $this->loadModels();
IPF_ORM_Manager::getInstance()->setAttribute(IPF_ORM::ATTR_VALIDATE, IPF_ORM::VALIDATE_ALL);
$this->router = new IPF_Router();
$this->router->dispatch(IPF_HTTP_URL::getAction());
diff --git a/ipf/session/models/_generated/BaseSession.php b/ipf/session/models/_generated/BaseSession.php
index 741b93d..b126310 100644
--- a/ipf/session/models/_generated/BaseSession.php
+++ b/ipf/session/models/_generated/BaseSession.php
@@ -1,7 +1,7 @@