Changeset 500

Show
Ignore:
Timestamp:
06/28/08 01:39:45 (6 months ago)
Author:
padams
Message:

adding update framework and refactored entity manager and db abstraction layer.
moved perform action into api from caller.
added schema update to make tables transactional under mysql

Location:
trunk
Files:
1 added
2 removed
13 modified

Legend:

Unmodified
Added
Removed
  • trunk/conf/messages.php

    r498 r500  
    46462503 => array("Options reset to Default Values.",0), 
    4747 
     48 
    4849//User managment 
    49503000 => array("Success. User Added.", 0), 
     
    74753305 => array("Success. Base Database Schema Installed.",0), 
    75763306 => array("Error. User id already exists for some reason.",0), 
     773307 => array("Updates failed. Check the log file for more details and try again.",0), 
    7678 
    7779// Graph related 
  • trunk/modules/base/classes/entityManager.php

    r498 r500  
    9696        function create() {      
    9797                 
    98                 $all_cols = $this->entity->getColumns(); 
    99                  
    100                 $cols = array(); 
    101                  
    102                 // Control loop 
    103                 foreach ($all_cols as $k => $v){ 
    104                  
    105                         // drop column is it is marked as auto-incement as DB will take car of that. 
    106                         if ($this->entity->$v->auto_increment == true): 
    107                                 break; 
    108                         else: 
    109                                 $cols[$v] = $this->entity->$v->value; 
    110                         endif; 
    111                                  
    112                 } 
    113          
    114                 // Persist object 
    115                 $status = $this->db->save($cols, get_class($this->entity)); 
    116                  
    117                 // Add to Cache 
    118                  
    119                 if ($status == true): 
    120                         if ($this->config['cache_objects'] == true): 
    121                                 $this->cache->set(get_class($this->entity), 'id'.$this->entity->id->value, $this->entity); 
    122                         endif; 
    123                 endif; 
    124                  
    125                 return $status; 
     98                return $this->entity->create(); 
    12699                 
    127100        } 
     
    130103         * Create Table 
    131104         * 
    132          * Handled by DB abstraction layer because the SQ associated with this is way too DB specific 
     105         * Handled by DB abstraction layer because the SQL associated with this is way too DB specific 
    133106         */ 
    134107        function createTable() { 
     
    235208        function update($where = '') {   
    236209                 
    237                 if(empty($where)): 
    238                         $constraint = array('id' => $this->entity->id->value); 
    239                 else: 
    240                         $constraint = array($where => $this->entity->$where->value); 
    241                 endif; 
    242                  
    243                  
    244                 // Persist object 
    245                 $status = $this->db->update($this->_getProperties(), $constraint, get_class($this->entity)); 
    246                  
    247                 // Add to Cache 
    248                 if ($status == true): 
    249                         if ($this->config['cache_objects'] == true): 
    250                                 $this->cache->replace(get_class($this->entity), 'id'.$this->entity->id->value, $this->entity); 
    251                         endif; 
    252                 endif; 
    253                  
    254                 return $status; 
     210                $this->entity->update($where); 
    255211                 
    256212        } 
     
    265221        function partialUpdate($named_properties, $where) { 
    266222                 
    267                 $properties = array(); 
    268                  
    269                 foreach ($named_properties as $n) { 
    270                          
    271                         $properties[$n] = $this->entity->$n->value; 
    272                          
    273                 } 
    274                  
    275                                  
    276                 // Persist object 
    277                 $status = $this->db->update($properties, $where, get_class($this->entity)); 
    278                  
    279                 // Add to Cache 
    280                 if ($status == true): 
    281                         if ($this->config['cache_objects'] == true): 
    282                                 $this->cache->set(get_class($this->entity), 'id'.$this->entity->id->value, $this->entity); 
    283                         endif; 
    284                 endif; 
    285                  
    286                 return $status; 
     223                return $this->entity->partialUpdate($named_properties, $where); 
    287224                 
    288225        } 
     
    295232        function delete($id, $col = '') {        
    296233                                 
    297                 if (empty($col)): 
    298                         $col = 'id'; 
    299                 endif; 
    300                  
    301                 // Persist object 
    302                 $status = $this->db->delete($id, $col, get_class($this->entity)); 
    303          
    304                 // Add to Cache 
    305                 if ($status == true): 
    306                         if ($this->config['cache_objects'] == true): 
    307                                 $this->cache->remove(get_class($this->entity), 'id'.$this->entity->id->value); 
    308                         endif; 
    309                 endif; 
    310                  
    311                 return $status; 
    312                  
     234                return $this->entity->delete($id, $col);         
    313235        } 
    314236         
    315237        function getByPk($col, $value) { 
    316238                 
    317                 return $this->getByColumn($col, $value); 
     239                return $this->entity->getByColumn($col, $value); 
    318240                 
    319241        } 
     
    321243        function getByColumn($col, $value) { 
    322244                 
    323                 $cache_obj = ''; 
    324                  
    325                 if ($this->config['cache_objects'] == true): 
    326                         $cache_obj = $this->cache->get(get_class($this->entity), $col.$value); 
    327                 endif; 
    328                          
    329                 if (!empty($cache_obj)): 
    330                  
    331                         $this->entity = $cache_obj; 
    332                                          
    333                 else: 
    334                  
    335                         $constraint = array($col => $value); 
    336                                  
    337                         $properties = $this->db->select($this->_getProperties(), $constraint, get_class($this->entity)); 
    338                          
    339                         if (!empty($properties)): 
    340                                          
    341                                 $this->setProperties($properties); 
    342                                  
    343                                 if ($this->config['cache_objects'] == true): 
    344                                         $this->cache->set(get_class($this->entity), 'id'.$this->entity->id->value, $this->entity);       
    345                                 endif;           
    346                         endif; 
    347                 endif; 
    348                  
    349                 return;  
     245                return $this->entity->getByColumn($col, $value); 
     246                 
    350247        } 
    351248         
     
    402299        } 
    403300         
    404          
     301        /** 
     302         * Sets Values/Properties 
     303         * @depricated use setProperties() 
     304         */ 
    405305        function setValues($values) { 
    406306                 
    407                 $properties = array_keys(get_object_vars($this->entity)); 
    408                  
    409                 foreach ($properties as $k => $v) { 
    410                                  
    411                                 $this->entity->$v->value = $values[$v]; 
    412                  
    413                         } 
    414                  
    415                 return; 
     307                return $this->setProperties($values); 
    416308                 
    417309        } 
  • trunk/modules/base/module.php

    r498 r500  
    4343                $this->description = 'Base functionality for OWA.'; 
    4444                $this->config_required = false; 
    45                 $this->required_schema_version = 1; 
     45                $this->required_schema_version = 3; 
    4646                 
    4747                 
    4848                $this->owa_module(); 
    49                 $this->c->set('base', 'schema_version', '1'); 
     49                //$this->c->set('base', 'schema_version', '1'); 
    5050                return; 
    5151        } 
  • trunk/modules/base/updatesApply.php

    r499 r500  
    5151                 
    5252                $modules = $api->getModulesNeedingUpdates(); 
     53                //print_r($modules); 
     54                //return; 
    5355                 
    5456                // foreach do update in order 
     57                 
     58                $error = false; 
    5559                 
    5660                foreach ($modules as $k => $v) { 
     
    5963                         
    6064                        if ($ret != true): 
     65                                $error = true; 
    6166                                break; 
    6267                        endif; 
    6368                 
    6469                } 
     70                 
     71                if ($error == true): 
     72                        $data['error_msg'] = 'something went wrong here with the updates.'; 
     73                        $data['view'] = 'base.error'; 
     74                        $data['view_method'] = 'delegate';                       
     75                else: 
    6576                         
    66                 // add data to container 
    67                 $this->data['status_code'] = ''; 
    68                 $this->data['do'] = 'base.optionsGeneral'; 
    69                 $this->data['view_method'] = 'delegate'; 
     77                        // add data to container 
     78                        $data['status_code'] = 3307; 
     79                        $data['do'] = 'base.optionsGeneral'; 
     80                        $data['view_method'] = 'redirect'; 
     81                  
     82                endif;           
    7083                 
    71                 return $this->data; 
     84                return $data; 
     85         
    7286         
    7387        } 
  • trunk/modules/hello/module.php

    r498 r500  
    4343                $this->description = 'Hello world sample module.'; 
    4444                $this->config_required = false; 
    45                 $this->required_schema_version = 2; 
     45                $this->required_schema_version = 1; 
    4646                 
    4747                $this->owa_module(); 
     48                //$this->c->set('hello', 'schema_version', '1'); 
    4849                 
    4950                return; 
  • trunk/owa_caller.php

    r499 r500  
    287287        function logEvent($event_type, $caller_params = '') { 
    288288                 
    289                 $this->e->debug(print_r($this->e->backtrace(), true)); 
     289                if ($this->c->get('base', 'error_log_level') > 9): 
     290                        $this->e->debug(print_r($this->e->backtrace(), true)); 
     291                endif; 
     292                 
    290293                //change config value to incomming site_id 
    291294                if(!empty($caller_params['site_id'])): 
     
    403406         * 
    404407         * @param array $caller_data 
     408         * @depricated 
    405409         * @return string 
    406410         */ 
     
    426430        /** 
    427431         * Displays a View without user authentication. Takes array of data as input 
    428          * 
     432         * @depricated 
    429433         * @param array $data 
    430434         */ 
     
    437441        } 
    438442         
    439         /** 
    440          * Invokes controller to perform controller 
    441          * 
    442          * @param $action string 
    443          *  
    444          */ 
    445         function performAction($action) { 
    446                  
    447                 // Load  
    448                 $controller = $this->api->moduleFactory($action, 'Controller', $this->params); 
    449                  
    450                 //perfrom authentication 
    451                 //$auth = &owa_auth::get_instance(); 
    452                  
    453                 //$data = $auth->authenticateUser($controller->priviledge_level); 
    454                  
    455                 // if auth was success then procead to do action specified in the intended controller. 
    456                 //if ($data['auth_status'] == true): 
    457                         $data = $controller->doAction(); 
    458                 //endif; 
    459                  
    460                 // Display view if controller calls for one. 
    461                 if (!empty($data['view']) || !empty($data['action'])): 
    462                  
    463                         //  
    464                         if ($data['view_method'] == 'delegate'): 
    465                                 return $this->api->displayView($data); 
    466                          
    467                         // Redirect to a view    
    468                         elseif ($data['view_method'] == 'redirect'): 
    469                                 owa_lib::redirectToView($data); 
    470                                 return; 
    471                                  
    472                         // return an image . Will output headers and binary data. 
    473                         elseif ($data['view_method'] == 'image'): 
    474                                 return $this->api->displayImage($data); 
    475                          
    476                         else: 
    477                                 return $this->api->displayView($data); 
    478                                  
    479                         endif; 
    480                  
    481                 elseif(!empty($data['do'])): 
    482                  
    483                         if ($data['view_method'] == 'redirect'): 
    484                                 owa_lib::redirectToView($data); 
    485                                 return; 
    486                         endif; 
    487                 endif; 
    488                  
    489                 return; 
    490                  
    491         } 
    492  
    493443         
    494444        /** 
     
    502452                 
    503453                // Override request parsms with those passed by caller 
    504                 // TODO: make this an array merge 
    505454                if (!empty($caller_params)): 
    506                  
    507                         foreach ($caller_params as $n => $v) { 
    508                                 $this->params[$n] = $v; 
    509                         } 
    510                  
     455                        $this->params = array_merge($this->params, $caller_params); 
    511456                endif; 
    512457                 
     
    516461                                 
    517462                if (!empty($this->params['action'])): 
    518                         $result =  $this->performAction($this->params['action']); 
     463                        $result = owa_coreAPI::performAction($this->params['action'], $this->params); 
    519464                        unset($this->params['action']); 
    520465                         
    521466                elseif (!empty($this->params['do'])): 
    522                         $result =  $this->performAction($this->params['do']);    
     467                        $result = owa_coreAPI::performAction($this->params['do'], $this->params);        
    523468                        //unset($this->params['action']); 
    524469                         
    525470                elseif ($this->params['view']): 
    526471                        // its a view request so the only data is in whats in the params 
    527                         $result = $this->renderView($this->params); 
     472                        $result = owa_coreAPI::displayView($this->params); 
    528473                        unset($this->params['view']); 
    529474                         
  • trunk/owa_coreAPI.php

    r498 r500  
    374374        } 
    375375         
    376         function updateFactory($module, $class) { 
     376        function updateFactory($module, $filename) { 
    377377         
    378378                require_once(OWA_BASE_CLASS_DIR.'update.php'); 
    379379                 
    380                 $obj = owa_coreAPI::moduleGenericFactory($module, 'updates', $class, '_update'); 
     380                //$obj = owa_coreAPI::moduleGenericFactory($module, 'updates', $filename, '_update'); 
     381                $class = 'owa_'.$module.'_'.$filename.'_update'; 
     382         
     383                // Require class file if class does not already exist 
     384                if(!class_exists($class)):       
     385                        owa_coreAPI::moduleRequireOnce($module, 'updates', $filename); 
     386                endif; 
     387                         
     388                $obj = owa_lib::factory(OWA_DIR.'modules'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'updates', '', $class, $params); 
     389 
    381390                $obj->module_name = $module; 
    382391                return $obj; 
     
    648657        } 
    649658         
     659        /** 
     660         * Invokes controller to perform controller 
     661         * 
     662         * @param $action string 
     663         *  
     664         */ 
     665        function performAction($action, $params = array()) { 
     666                 
     667                // Load  
     668                $controller = owa_coreAPI::moduleFactory($action, 'Controller', $params); 
     669                 
     670                $data = $controller->doAction(); 
     671                                 
     672                // Display view if controller calls for one. 
     673                if (!empty($data['view']) || !empty($data['action'])): 
     674                 
     675                        //  
     676                        if ($data['view_method'] == 'delegate'): 
     677                                return owa_coreAPI::displayView($data); 
     678                         
     679                        // Redirect to a view    
     680                        elseif ($data['view_method'] == 'redirect'): 
     681                                owa_lib::redirectToView($data); 
     682                                return; 
     683                                 
     684                        // return an image . Will output headers and binary data. 
     685                        elseif ($data['view_method'] == 'image'): 
     686                                return owa_coreAPI::displayImage($data); 
     687                         
     688                        else: 
     689                                return owa_coreAPI::displayView($data); 
     690                                 
     691                        endif; 
     692                 
     693                elseif(!empty($data['do'])): 
     694                        //print_r($data); 
     695                        owa_lib::redirectToView($data); 
     696                        return; 
     697                         
     698                endif; 
     699                 
     700                 
     701                 
     702        } 
     703         
     704        /** 
     705         * Logs an event to the event queue 
     706         *  
     707         * This function sets the action to be perfromed, santizes,  
     708         * and adds all of PHP's $_SERVER vars to the $caller_params. 
     709         * $_REQUEST vars are already added to $this->params in the constructor. 
     710         * 
     711         * @param array $caller_params 
     712         * @param string $event_type 
     713         * @return boolean 
     714         */ 
     715        function logEvent($event_type, $caller_params = '') { 
     716                 
     717                $c = owa_coreAPI::configSingleton(); 
     718                $e = owa_coreAPI::errorSingleton(); 
     719                $request_params = owa_coreAPI::requestContainer(); 
     720                 
     721                if ($c->get('base', 'error_log_level') > 9): 
     722                        $e->debug(print_r($e->backtrace(), true)); 
     723                endif; 
     724                 
     725                // do not log if the do not log param is set by caller. 
     726                if ($request_params['do_not_log'] == true): 
     727                        $e->debug("ABORTING LOG ACTION: do not log flag appears to be set"); 
     728                        return false; 
     729                endif; 
     730                 
     731                //change config value to incomming site_id 
     732                if(!empty($caller_params['site_id'])): 
     733                        $c->set('base', 'site_id', $caller_params['site_id']); 
     734                else: 
     735                        $caller_params['site_id'] = $c->get('base', 'site_id'); 
     736                endif; 
     737                 
     738                // do not log if the request is from a reserved IP 
     739                // ips = $this->c->get('base', 'log_not_log_ips'); 
     740                //      ... 
     741                 
     742                $params = array(); 
     743                // Add PHP's $_SERVER scope variables to event properties 
     744                $params['server'] = $_SERVER; 
     745                 
     746                // Apply caller's params to event properties 
     747                if (!empty($caller_params)): 
     748                        $params['caller'] = $caller_params; 
     749                endif; 
     750                 
     751                // set controller to invoke 
     752                $params['action'] = $event_type; 
     753                 
     754                // Filter input 
     755                $params = owa_lib::inputFilter($params); 
     756                 
     757                //Load browscap 
     758                $bcap = owa_coreAPI::supportClassFactory('base', 'browscap', $params['server']['HTTP_USER_AGENT']); 
     759                 
     760                // Abort if the request is from a robot 
     761                if ($c->get('base', 'log_robots') != true): 
     762                        if ($bcap->robotCheck() == true): 
     763                                $e->debug("ABORTING LOG ACTION: request appears to be from a robot"); 
     764                                return; 
     765                        endif; 
     766                endif; 
     767                 
     768                // Fetch browser capabilities and and apply to event params 
     769                $params['browscap'] = get_object_vars($bcap->browser); 
     770         
     771                return owa_coreAPI::handleRequest($params); 
     772                 
     773        } 
     774         
    650775} 
    651776 
  • trunk/owa_entity.php

    r498 r500  
    127127         
    128128        } 
     129         
     130        /** 
     131         * Persist new object 
     132         * 
     133         */  
     134        function create() {      
     135                 
     136                $db = owa_coreAPI::dbSingleton(); 
     137                $config = owa_coreAPI::configSingleton(); 
     138                $cache = owa_coreAPI::cacheSingleton(); 
     139                 
     140                $all_cols = $this->getColumns(); 
     141                 
     142                $cols = array(); 
     143                 
     144                // Control loop 
     145                foreach ($all_cols as $k => $v){ 
     146                 
     147                        // drop column is it is marked as auto-incement as DB will take care of that. 
     148                        if ($this->$v->auto_increment == true): 
     149                                ; 
     150                        else: 
     151                                $cols