fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [8623] Rental: move cron-function from ui to so-class


From: Sigurd Nes
Subject: [Fmsystem-commits] [8623] Rental: move cron-function from ui to so-class
Date: Fri, 20 Jan 2012 13:33:45 +0000

Revision: 8623
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=8623
Author:   sigurdne
Date:     2012-01-20 13:33:44 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
Rental: move cron-function from ui to so-class

Modified Paths:
--------------
    trunk/rental/inc/class.soadjustment.inc.php
    trunk/rental/inc/class.soparty.inc.php
    trunk/rental/inc/class.soworkbench_notification.inc.php
    trunk/rental/inc/class.uiparty.inc.php
    trunk/rental/setup/setup.inc.php
    trunk/rental/setup/tables_update.inc.php

Modified: trunk/rental/inc/class.soadjustment.inc.php
===================================================================
--- trunk/rental/inc/class.soadjustment.inc.php 2012-01-19 13:21:48 UTC (rev 
8622)
+++ trunk/rental/inc/class.soadjustment.inc.php 2012-01-20 13:33:44 UTC (rev 
8623)
@@ -4,7 +4,7 @@
 phpgw::import_class('rental.socontract_price_item');
 phpgw::import_class('rental.soprice_item');
 phpgw::import_class('rental.soworkbench_notification');
-phpgw::import_class('rental.uicommon');
+//phpgw::import_class('rental.uicommon');
 
 include_class('rental', 'adjustment', 'inc/model/');
 include_class('rental', 'contract_price_item', 'inc/model/');

Modified: trunk/rental/inc/class.soparty.inc.php
===================================================================
--- trunk/rental/inc/class.soparty.inc.php      2012-01-19 13:21:48 UTC (rev 
8622)
+++ trunk/rental/inc/class.soparty.inc.php      2012-01-20 13:33:44 UTC (rev 
8623)
@@ -1,6 +1,7 @@
 <?php
 
 phpgw::import_class('rental.socommon');
+phpgw::import_class('rental.bofellesdata');
 
 include_class('rental', 'agresso_cs15', 'inc/model/');
 include_class('rental', 'party', 'inc/model/');
@@ -9,6 +10,11 @@
 
 class rental_soparty extends rental_socommon
 {
+       const LOCATION_ROOT = '.';
+       const LOCATION_IN = '.RESPONSIBILITY.INTO';
+       const LOCATION_OUT = '.RESPONSIBILITY.OUT';
+       const LOCATION_INTERNAL = '.RESPONSIBILITY.INTERNAL';
+
        protected static $so;
 
        /**
@@ -433,6 +439,111 @@
                        return true;
                }
        }
+
+ 
+               /**
+                * Check to see if this user is an administrator
+                * 
+                * @return true if private permission on root, false otherwise
+                */
+
+               protected function isAdministrator()
+               {
+                       return 
$GLOBALS['phpgw']->acl->check(self::LOCATION_ROOT,PHPGW_ACL_PRIVATE,'rental');
+               }
+               
+               /**
+                * Check to see if the user is an executive officer
+                * 
+                * @return true if at least add permission on fields of 
responsibilities (locations: .RESPONSIBIITY.*)
+                */
+               protected function isExecutiveOfficer()
+               {
+                       return (
+                               
$GLOBALS['phpgw']->acl->check(self::LOCATION_IN,PHPGW_ACL_ADD,'rental') ||
+                               
$GLOBALS['phpgw']->acl->check(self::LOCATION_OUT,PHPGW_ACL_ADD,'rental')        
||
+                               
$GLOBALS['phpgw']->acl->check(self::LOCATION_INTERNAL,PHPGW_ACL_ADD,'rental')
+                       );
+               }
+
+       /**
+        * Synchronization job to update company name on contract parties which 
are connected to Fellesdata.
+        * 
+        * Uses property org_enhet_id on party to link party with unit from 
Fellesdata.
+        * To be run as a scheduled job
+        */
+       function syncronize_party_name()
+       {
+               $config = CreateObject('phpgwapi.config','rental');
+               $config->read();
+
+               $use_fellesdata = $config->config_data['use_fellesdata'];       
+               if(!$use_fellesdata){
+                       return;
+               }
+               $bofelles = rental_bofellesdata::get_instance();
+
+               $parties = rental_soparty::get_instance()->get();
+               $result_count = rental_soparty::get_instance()->get_count();
+               $updated_parties;
+               
+               $updated_parties[] = "Total number of parties: {$result_count}";
+               
+               if(($this->isExecutiveOfficer() || $this->isAdministrator()))
+               {
+                       $count = 0;
+                       $count_result_unit_number = 0;
+                       $count_identifier = 0;
+                       $count_responsibility = 0;
+
+                       foreach ($parties as $party) {
+                               $unit_found = false;
+                               $fellesdata = NULL;
+
+                               if(isset($party)) {
+                                       $sync_data = $party->get_sync_data();
+
+                                       $fellesdata = 
$bofelles->result_unit_exist($sync_data['result_unit_number'],4);
+                                       if ($fellesdata) {
+                                               $updated_parties[] = "Unit id 
found {$fellesdata['UNIT_ID']} by result unit number check. The unit name is 
{$fellesdata['UNIT_NAME']}<br />";
+                                               $count_result_unit_number++;
+                                       }
+
+                                       if ($fellesdata && 
isset($fellesdata['UNIT_ID']) && is_numeric($fellesdata['UNIT_ID'])) {
+                                               // We found a match, so store 
the new connection
+                                               
$party->set_org_enhet_id($fellesdata['UNIT_ID']);
+                                               $old_party_name = 
$party->get_company_name();
+                                               
$party->set_company_name($fellesdata['UNIT_NAME']);
+                                               $updated_parties[] = "Updated 
company name on party {$party->get_id()} with unit ID 
{$party->get_org_enhet_id} from {$old_party_name} to 
{$party->get_company_name()}";
+                                               $count++;
+                                       } else {
+                                               // No match was found. Do 
nothing
+                                               
//$party->set_org_enhet_id(NULL);
+                                       }
+                                       
rental_soparty::get_instance()->store($party);
+                               }
+                       }
+
+                       $updated_parties[] = "Number of parties found through 
result unit number {$count_result_unit_number}";
+                       $updated_parties[] = "Number of parties that have been 
updated {$count}";
+                       $this->log_sync_messages($updated_parties);
+               }
+       }
+       
+       private function log_sync_messages($messages)
+       {
+               $msgs = array_merge(
+                       array('---------------Messages-------------------'),
+                       $messages
+               );
+                       
+               //use PHPGW tmp-catalog to store log-file
+               $path = $GLOBALS['phpgw_info']['server']['temp_dir'];
+                       
+               //Write to the log-file
+               $date_now = date('Y-m-d');
+               file_put_contents("{$path}/FD_name_sync_{$date_now}.log", 
implode(PHP_EOL, $msgs));
+       }
        
 }
-?>
+

Modified: trunk/rental/inc/class.soworkbench_notification.inc.php
===================================================================
--- trunk/rental/inc/class.soworkbench_notification.inc.php     2012-01-19 
13:21:48 UTC (rev 8622)
+++ trunk/rental/inc/class.soworkbench_notification.inc.php     2012-01-20 
13:33:44 UTC (rev 8623)
@@ -139,4 +139,4 @@
                else { return false; }
        }
 }
-?>
\ No newline at end of file
+?>

Modified: trunk/rental/inc/class.uiparty.inc.php
===================================================================
--- trunk/rental/inc/class.uiparty.inc.php      2012-01-19 13:21:48 UTC (rev 
8622)
+++ trunk/rental/inc/class.uiparty.inc.php      2012-01-20 13:33:44 UTC (rev 
8623)
@@ -269,86 +269,6 @@
                }
        }
        
-       /**
-        * Synchronization job to update company name on contract parties which 
are connected to Fellesdata.
-        * 
-        * Uses property org_enhet_id on party to link party with unit from 
Fellesdata.
-        * To be run as a scheduled job
-        */
-       function syncronize_party_name()
-       {
-               $config = CreateObject('phpgwapi.config','rental');
-               $config->read();
-
-               $use_fellesdata = $config->config_data['use_fellesdata'];       
-               if(!$use_fellesdata){
-                       return;
-               }
-               $bofelles = rental_bofellesdata::get_instance();
-
-               $parties = rental_soparty::get_instance()->get();
-               $result_count = rental_soparty::get_instance()->get_count();
-               $updated_parties;
-               
-               $updated_parties[] = "Total number of parties: {$result_count}";
-               
-               if(($this->isExecutiveOfficer() || $this->isAdministrator()))
-               {
-                       $count = 0;
-                       $count_result_unit_number = 0;
-                       $count_identifier = 0;
-                       $count_responsibility = 0;
-
-                       foreach ($parties as $party) {
-                               $unit_found = false;
-                               $fellesdata = NULL;
-
-                               if(isset($party)) {
-                                       $sync_data = $party->get_sync_data();
-
-                                       $fellesdata = 
$bofelles->result_unit_exist($sync_data['result_unit_number'],4);
-                                       if ($fellesdata) {
-                                               $updated_parties[] = "Unit id 
found {$fellesdata['UNIT_ID']} by result unit number check. The unit name is 
{$fellesdata['UNIT_NAME']}<br />";
-                                               $count_result_unit_number++;
-                                       }
-
-                                       if ($fellesdata && 
isset($fellesdata['UNIT_ID']) && is_numeric($fellesdata['UNIT_ID'])) {
-                                               // We found a match, so store 
the new connection
-                                               
$party->set_org_enhet_id($fellesdata['UNIT_ID']);
-                                               $old_party_name = 
$party->get_company_name();
-                                               
$party->set_company_name($fellesdata['UNIT_NAME']);
-                                               $updated_parties[] = "Updated 
company name on party {$party->get_id()} with unit ID 
{$party->get_org_enhet_id} from {$old_party_name} to 
{$party->get_company_name()}";
-                                               $count++;
-                                       } else {
-                                               // No match was found. Do 
nothing
-                                               
//$party->set_org_enhet_id(NULL);
-                                       }
-                                       
rental_soparty::get_instance()->store($party);
-                               }
-                       }
-
-                       $updated_parties[] = "Number of parties found through 
result unit number {$count_result_unit_number}";
-                       $updated_parties[] = "Number of parties that have been 
updated {$count}";
-                       $this->log_sync_messages($updated_parties);
-               }
-       }
-       
-       private function log_sync_messages($messages)
-       {
-               $msgs = array_merge(
-                       array('---------------Messages-------------------'),
-                       $messages
-               );
-                       
-               //use PHPGW tmp-catalog to store log-file
-               $path = $GLOBALS['phpgw_info']['server']['temp_dir'];
-                       
-               //Write to the log-file
-               $date_now = date('Y-m-d');
-               file_put_contents("{$path}/FD_name_sync_{$date_now}.log", 
implode(PHP_EOL, $msgs));
-       }
-       
-
        /**
         * Add action links for the context menu of the list item
         *

Modified: trunk/rental/setup/setup.inc.php
===================================================================
--- trunk/rental/setup/setup.inc.php    2012-01-19 13:21:48 UTC (rev 8622)
+++ trunk/rental/setup/setup.inc.php    2012-01-20 13:33:44 UTC (rev 8623)
@@ -1,6 +1,6 @@
 <?php
        $setup_info['rental']['name'] = 'rental';               // Module 
identifier
-       $setup_info['rental']['version'] = '0.1.0.15';  // Current module 
version
+       $setup_info['rental']['version'] = '0.1.0.16';  // Current module 
version
        $setup_info['rental']['app_order'] = 51;                // (?)
        $setup_info['rental']['tables'] = array(
                'rental_party',                                         // All 
contract participants, tenants etc.

Modified: trunk/rental/setup/tables_update.inc.php
===================================================================
--- trunk/rental/setup/tables_update.inc.php    2012-01-19 13:21:48 UTC (rev 
8622)
+++ trunk/rental/setup/tables_update.inc.php    2012-01-20 13:33:44 UTC (rev 
8623)
@@ -267,4 +267,23 @@
                $GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.15';
                return $GLOBALS['setup_info']['rental']['currentver'];
        }
-?>
\ No newline at end of file
+
+       /*
+       * function moved to so-class
+       */
+       $test[] = '0.1.0.15';
+       function rental_upgrade0_1_0_15()
+       {
+               $asyncservice = CreateObject('phpgwapi.asyncservice');
+               $asyncservice->delete('rental_sync_party_name');
+               $asyncservice->set_timer(
+                       array('day' => "*/1"),
+                       'rental_sync_party_name',
+                       'rental.soparty.syncronize_party_name',
+                       null
+                       );
+               
+               $GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.16';
+               return $GLOBALS['setup_info']['rental']['currentver'];
+       }
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]