]> git.andy128k.dev Git - ipf.git/commitdiff
Import Scheme refactor
authoravl <alex.litovchenko@gmail.com>
Fri, 29 Aug 2008 02:41:00 +0000 (04:41 +0200)
committeravl <alex.litovchenko@gmail.com>
Fri, 29 Aug 2008 02:41:00 +0000 (04:41 +0200)
14 files changed:
ipf/admin/models/_generated/BaseAdminLog.php
ipf/application.php
ipf/auth/models/_generated/BasePermission.php
ipf/auth/models/_generated/BaseRole.php
ipf/auth/models/_generated/BaseRolePermission.php
ipf/auth/models/_generated/BaseUser.php
ipf/auth/models/_generated/BaseUserPermission.php
ipf/auth/models/_generated/BaseUserRole.php
ipf/cli.php
ipf/form.php
ipf/orm/import/builder.php
ipf/orm/import/schema.php
ipf/project.php
ipf/session/models/_generated/BaseSession.php

index e7114fc805b900535b81d0350d560308083606df..930e5eb311643c9d636a349d91fe0d37114684f0 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework
  */
 abstract class BaseAdminLog extends IPF_ORM_Record
 {
index d230bd3aff795dc3b28ade245af63980ee52fd44..a357444e49f93b0dad1470204d0d0044f67eb119 100644 (file)
@@ -60,8 +60,6 @@ abstract class IPF_Application{
     }
     
     public function generateModels(){
-        //if (count($this->models)==0)
-        //   return;
         IPF_ORM::generateModelsFromYaml($this->path.'models.yml', $this->path.'models');
     }
 
index 38134759912b80755ca3140541b7e276710a96e1..4be989166a207f7637725be1ec0f60efc7f58064 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework
  */
 abstract class BasePermission extends IPF_ORM_Record
 {
index 6fa37d53ac072e77986cbde3c6078b5ac62e13b8..6486330b9935c3d9eb8579106c2cb1cef952c796 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework
  */
 abstract class BaseRole extends IPF_ORM_Record
 {
index 6a499b7917ec5a9fb768cd0281bdf85a7f0c4a2b..807bb5b41758bd40dc18d6ec70baff88ae714aa1 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework
  */
 abstract class BaseRolePermission extends IPF_ORM_Record
 {
index 1027aab616775872346201a27e2988022f39f79d..85e5e88255959c4b074f4c52b2da8bc9b3bc5b9a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework
  */
 abstract class BaseUser extends IPF_ORM_Record
 {
index 8ffd722e78d193c1c377a29ebe412b0a09662f1c..988247a0b3eb7c62052d52ddad4ad41a4f097ea0 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework
  */
 abstract class BaseUserPermission extends IPF_ORM_Record
 {
index 64881bb42f89c2d48530fa4d569026e87755687d..363ff0113f56b57cc1cde250038fac95e7c606d2 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework
  */
 abstract class BaseUserRole extends IPF_ORM_Record
 {
index 74222a14bbec7de2137d163475c7783554772945..9d1fc2879c06402a40cbc1cdc114a8776d08ca56 100644 (file)
@@ -26,6 +26,7 @@ class IPF_Cli{
     
     protected function sql(&$args){
         print "Show All Sql DDL From Model Classes\n";
+        IPF_Project::getInstance()->loadModels();
         print IPF_Project::getInstance()->generateSql();
     }
 
index 3ab6c0d9151bd048b04fa413c630162a6853c791..40d7518b3edceaf41e607c9ef947b15300d3189f 100644 (file)
@@ -194,14 +194,12 @@ class IPF_Form implements Iterator
 
     public function render_p()
     {
-        return $this->htmlOutput('<p>%1$s%2$s %3$s%4$s</p>', '%s', '</p>', 
-                                 ' %s', true);
+        return $this->htmlOutput('<p>%1$s%2$s %3$s%4$s</p>', '%s', '</p>', ' %s', true);
     }
 
     public function render_ul()
     {
-        return $this->htmlOutput('<li>%1$s%2$s %3$s%4$s</li>', '<li>%s</li>', 
-                                 '</li>', ' %s', false);
+        return $this->htmlOutput('<li>%1$s%2$s %3$s%4$s</li>', '<li>%s</li>', '</li>', ' %s', false);
     }
 
     public function render_table()
@@ -266,3 +264,4 @@ function IPF_Form_renderErrorsAsHTML($errors)
     }
     return '<ul class="errorlist">'.implode("\n", $tmp).'</ul>';
 }
+
index 34d683faeab5fb535b50c6c038a26d9efb724692..2b996afdcd035ecf32ffe5b6a6306e9fc5a0f69f 100644 (file)
@@ -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']) {
index b8c64aaf88ad2250bfb4e895bbe22255bd453870..e44ac1c3a3df9da2bb0c35f356b52497b2caa3fb 100644 (file)
@@ -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 . '" 
index 932c29048057c8b6749af75f169df46c23c35327..0c8b38dc931a7f3a078f0ec249fc2747648f792e 100644 (file)
@@ -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()); 
index 741b93d15e312e39a92ddd52441540eb8bda06e7..b126310ad95b67c03a8cfdd6c689a5e92b3fdb74 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework
  */
 abstract class BaseSession extends IPF_ORM_Record
 {