Example #1
0
function MakeArchiveFileName($iRefTime = null)
{
    $sDefaultBackupFileName = sys_get_temp_dir() . '/' . "__DB__-%Y-%m-%d";
    $sBackupFile = utils::ReadParam('backup_file', $sDefaultBackupFileName, true, 'raw_data');
    $oConfig = new Config(APPCONF . 'production/config-itop.php');
    $sBackupFile = str_replace('__HOST__', $oConfig->GetDBHost(), $sBackupFile);
    $sBackupFile = str_replace('__DB__', $oConfig->GetDBName(), $sBackupFile);
    $sBackupFile = str_replace('__SUBNAME__', $oConfig->GetDBSubName(), $sBackupFile);
    if (is_null($iRefTime)) {
        $sBackupFile = strftime($sBackupFile);
    } else {
        $sBackupFile = strftime($sBackupFile, $iRefTime);
    }
    return $sBackupFile . '.zip';
}
 static function GetPreviousInstance($sDir)
 {
     $bFound = false;
     $sSourceDir = '';
     $sSourceEnvironement = '';
     $sConfigFile = '';
     $aResult = array('found' => false);
     if (file_exists($sDir . '/config-itop.php')) {
         $sSourceDir = $sDir;
         $sSourceEnvironment = '';
         $sConfigFile = $sDir . '/config-itop.php';
         $aResult['found'] = true;
     } else {
         if (file_exists($sDir . '/conf/production/config-itop.php')) {
             $sSourceDir = $sDir;
             $sSourceEnvironment = 'production';
             $sConfigFile = $sDir . '/conf/production/config-itop.php';
             $aResult['found'] = true;
         }
     }
     if ($aResult['found']) {
         $oPrevConf = new Config($sConfigFile);
         $aResult = array('found' => true, 'source_dir' => $sSourceDir, 'source_environment' => $sSourceEnvironment, 'configuration_file' => $sConfigFile, 'db_server' => $oPrevConf->GetDBHost(), 'db_user' => $oPrevConf->GetDBUser(), 'db_pwd' => $oPrevConf->GetDBPwd(), 'db_name' => $oPrevConf->GetDBName(), 'db_prefix' => $oPrevConf->GetDBSubname());
     }
     return $aResult;
 }
Example #3
0
 function get_prod($sku, $locking = true, $i = 0)
 {
     if ($locking == true) {
         //locking mechanism - two users can't access the same site at the same time
         $FeedsDbObj = Config::GetDBName(Config::DATABASE_FEEDS);
         //$FeedsDbObj->StartTransaction ();
         $lock = $FeedsDbObj->SelectAndReturnRow("select site from extractor_lock where site='{$this->site}' and created>date_add(now(), interval -2 minute)", TRUE);
         if (empty($lock)) {
             $FeedsDbObj->InsertRow("insert into extractor_lock (site, created) values ('{$this->site}', now())");
             //$FeedsDbObj->EndTransaction ();
             $res = $this->parser->get_prod($sku);
             $FeedsDbObj->DeleteRow("delete from extractor_lock where site='{$this->site}'");
         } else {
             //$FeedsDbObj->EndTransaction ();
             sleep(7);
             if ($i > 10) {
                 return "Server busy, try again";
             }
             $res = $this->get_prod($sku, $i + 1);
         }
     } else {
         $res = $this->parser->get_prod($sku);
     }
     return $res;
 }
Example #4
0
 public static function GetUserScreenAccess($PartyID)
 {
     $ScreensDbObj = Config::GetDBName(Config::DATABASE_SCREENS);
     $CleanParty = $ScreensDbObj->EscapeField($PartyID);
     $sqlStmt = "select Screen_Name from Screen_Access where Party_ID = {$CleanParty}";
     $Results = $ScreensDbObj->SelectAndReturnAllRows($sqlStmt, False, True);
     $UserScreenList = array();
     foreach ($Results as $Screen) {
         $UserScreenList[$Screen["Screen_Name"]] = null;
     }
     if (isset($_SESSION["USER"])) {
         $ScreenUser = trim($_SESSION["USER"]);
         if ($ScreenUser == $PartyID) {
             self::$UserScreenAccess = $UserScreenList;
         }
     }
     return $UserScreenList;
 }
 public function GetApplicationVersion(Config $oConfig)
 {
     $aResult = false;
     try {
         require_once APPROOT . '/core/cmdbsource.class.inc.php';
         CMDBSource::Init($oConfig->GetDBHost(), $oConfig->GetDBUser(), $oConfig->GetDBPwd(), $oConfig->GetDBName());
         CMDBSource::SetCharacterSet($oConfig->GetDBCharacterSet(), $oConfig->GetDBCollation());
         $sSQLQuery = "SELECT * FROM " . $oConfig->GetDBSubname() . "priv_module_install";
         $aSelectInstall = CMDBSource::QueryToArray($sSQLQuery);
     } catch (MySQLException $e) {
         // No database or erroneous information
         $this->log_error('Can not connect to the database: host: ' . $oConfig->GetDBHost() . ', user:'******', pwd:' . $oConfig->GetDBPwd() . ', db name:' . $oConfig->GetDBName());
         $this->log_error('Exception ' . $e->getMessage());
         return false;
     }
     // Scan the list of installed modules to get the version of the 'ROOT' module which holds the main application version
     foreach ($aSelectInstall as $aInstall) {
         $sModuleVersion = $aInstall['version'];
         if ($sModuleVersion == '') {
             // Though the version cannot be empty in iTop 2.0, it used to be possible
             // therefore we have to put something here or the module will not be considered
             // as being installed
             $sModuleVersion = '0.0.0';
         }
         if ($aInstall['parent_id'] == 0) {
             if ($aInstall['name'] == DATAMODEL_MODULE) {
                 $aResult['datamodel_version'] = $sModuleVersion;
                 $aComments = json_decode($aInstall['comment'], true);
                 if (is_array($aComments)) {
                     $aResult = array_merge($aResult, $aComments);
                 }
             } else {
                 $aResult['product_name'] = $aInstall['name'];
                 $aResult['product_version'] = $sModuleVersion;
             }
         }
     }
     if (!array_key_exists('datamodel_version', $aResult)) {
         // Versions prior to 2.0 did not record the version of the datamodel
         // so assume that the datamodel version is equal to the application version
         $aResult['datamodel_version'] = $aResult['product_version'];
     }
     $this->log_info("GetApplicationVersion returns: product_name: " . $aResult['product_name'] . ', product_version: ' . $aResult['product_version']);
     return $aResult;
 }
 public function __construct()
 {
     $this->OfbizDbObj = Config::GetDBName(Config::DATABASE_OFBIZ);
 }
 public function __construct($PartyID, $TableName, $GenericFeed = FALSE, $MiniFeed = FALSE)
 {
     $this->TableName = $TableName;
     $this->PartyID = $PartyID;
     $this->GenericFeed = $GenericFeed;
     $this->MiniFeed = $MiniFeed;
     $this->FeedsDbObj = Config::GetDBName(Config::DATABASE_FEEDS);
     $this->FeedsInsertObj = Config::GetDBName(Config::DATABASE_FEEDS2);
     $this->OfbizReadDB = Config::GetDBName(Config::DATABASE_OFBIZREADONLY);
     // Obtain current date and time from server, we use this for inventory timestamp
     $sqlStmt = "select now() as work_date";
     $sqlResult = $this->FeedsDbObj->SelectAndReturnRow($sqlStmt);
     $this->StartDateTime = $sqlResult["work_date"];
     if (is_null($PartyID)) {
         $this->IsMiniMSRP = TRUE;
     } else {
         // Check the supplier party id, and, if it does not exist, add it
         $SupplierObj = new OfbizSuppliers();
         $SupplierName = $SupplierObj->GetSupplierName($PartyID);
         if (is_null($SupplierName)) {
             $SupplierObj->CreateNewSupplier($PartyID, $PartyID);
         }
         if (!$MiniFeed) {
             $this->StartSeconds = time();
             $this->SqlStart = date("Y-m-d H:i:s");
             $sqlStmt = "select Current_Load_ID, Minimum_Records from Supplier_Control where Supplier_Party_ID = '{$PartyID}'";
             $results = $this->FeedsInsertObj->SelectAndReturnRow($sqlStmt);
             $this->LoadID = $results["Current_Load_ID"];
             $this->MinimumRecords = $results["Minimum_Records"];
             $sqlStmt = "insert ignore into Supplier_History (Supplier_Party_ID, Load_ID, Pull_Start) values ('{$this->PartyID}', {$this->LoadID}, '{$this->SqlStart}')";
             $this->FeedsInsertObj->InsertRow($sqlStmt);
             // Gather the list of disallowed supplier manufacturers
             $sqlStmt = "select smx.Supplier_Mfr_Name from Supplier_Manufacturer_Disallow smd, Supplier_Manufacturer_Xref smx where (smd.Supplier_Party_ID = '{$PartyID}' or smd.Supplier_Party_ID = 'ALL') and smd.MANUFACTURER_PARTY_ID = smx.Ofbiz_Manufacturer_ID and smx.Supplier_Party_ID = '{$PartyID}'";
             $MfrList = $this->FeedsDbObj->SelectAndReturnAllRows($sqlStmt, False, True);
             foreach ($MfrList as $MfrInfo) {
                 $workName = trim($MfrInfo["Supplier_Mfr_Name"]);
                 $workName = StripInvalidCharacters($workName);
                 if (empty($workName)) {
                     continue;
                 }
                 $workName = htmlspecialchars_decode($workName, ENT_QUOTES);
                 $this->SupplierMfrDisallow[] = $workName;
             }
             // Gather the list of prefixes to be removed for this Supplier Party
             $sqlStmt = "select pr.prefix, smx.Supplier_Mfr_Name from Prefix_Remover pr, Supplier_Manufacturer_Xref smx where pr.supplier_id = '{$PartyID}' and smx.Ofbiz_Manufacturer_ID = pr.manufacturer_id and smx.Supplier_Party_ID = pr.supplier_id";
             $PrefixList = $this->FeedsDbObj->SelectAndReturnAllRows($sqlStmt, False, True);
             foreach ($PrefixList as $PrefixInfo) {
                 $workName = trim($PrefixInfo["Supplier_Mfr_Name"]);
                 $workName = StripInvalidCharacters($workName);
                 if (empty($workName)) {
                     continue;
                 }
                 $workName = htmlspecialchars_decode($workName, ENT_QUOTES);
                 if (array_key_exists($workName, $this->SupplierPrefixes)) {
                     $this->SupplierPrefixes[$workName][] = "/^" . $PrefixInfo["prefix"] . "[-]*/";
                 } else {
                     $this->SupplierPrefixes[$workName] = array("/^" . $PrefixInfo["prefix"] . "[-]*/");
                 }
             }
             echo "Our prefix remover array is " . print_r($this->SupplierPrefixes);
         }
     }
     $this->FilesToPurge = array();
 }