function import() { $module = strtolower($this->module); if ($module == "dotnl") { $parser = new DotNLParser(); $registry = $this->registryFactory->GetRegistryByName('DotNL'); } else { if ($module == "rrpproxy") { $parser = new RRPProxyParser(); $registry = $this->registryFactory->GetRegistryByName('RRPProxy'); } } if ($parser == null) { throw new Exception("Cannot find line parser for module '{$module}'"); } // Import process $fp = $this->fopen($this->in); $headers = $this->fgetcsv($fp); for ($lineno = 1; !feof($fp); $lineno++) { $line = $this->fgetcsv($fp); $line = array_combine($headers, array_map('trim', $line)); try { $parseResult = $parser->parseLine($line); if (!$parseResult) { continue; } } catch (Exception $e) { print "Cannot parse line {$lineno}\n"; continue; } if ($this->dbContact->FindByCLID($parseResult['clid'])) { // Skip existing in database print "[{$parseResult['clid']}] Skipped. Already exists in database.\n"; continue; } // Construct contact $contact = $registry->NewContactInstanceByGroup($parseResult['group']); $contact->CLID = $parseResult['clid']; $contact->UserID = $this->userid; try { $contact->SetFieldList($parseResult['fields'], 1); } catch (ErrorList $e) { print "[{$contact->CLID}] Contact data violates manifest rules. " . join("; ", $e->GetAllMessages()) . "\n"; print "[{$contact->CLID}] Set non strict mode\n"; $contact->SetFieldList($parseResult['fields'], 0); } // Save contact try { $this->dbContact->Save($contact); print "[{$contact->CLID}] Imported\n"; } catch (Exception $e) { print "[{$contact->CLID}] Cannot save. {$e->getMessage()}\n"; } } fclose($fp); }
private function ConvertPricingOld() { $modules_data = $this->DbNew->GetAll('SELECT * FROM modules'); $package_column = $this->OldColumnExists('prices', 'packageid'); $extra_stmts = $package_column ? "AND packageid = '0'" : ""; foreach ($modules_data as $module) { $Registry = $this->RegistryFactory->GetRegistryByName($module['name']); $Manifest = $Registry->GetManifest(); foreach ($Manifest->GetExtensionList() as $tld) { $Manifest->SetExtension($tld); $section_config = $Manifest->GetSectionConfig(); $isActive = $this->DbOld->GetOne("SELECT DISTINCT isactive FROM prices WHERE TLD = ? AND isres = 0 {$extra_stmts}", array($tld)); $this->DbNew->Execute("INSERT INTO tlds SET TLD = ?, isactive = ?, modulename = ?", array($tld, (int) $isActive, $module['name'])); $prices = $this->DbOld->GetAll("SELECT * FROM prices WHERE TLD=? AND isres=0 {$extra_stmts}", array($tld)); foreach ($prices as $price) { if ($price["operation"] != 'Transfer' && $price["operation"] != 'Repair') { for ($i = (int) $section_config->domain->registration->min_period; $i <= (int) $section_config->domain->registration->max_period; $i++) { $this->DbNew->Execute("INSERT INTO prices SET purpose=?, cost=?, TLD=?, period=?", array($price['operation'], $price['cost'], $tld, $i)); } } elseif ($price["operation"] == 'Transfer') { $this->DbNew->Execute("INSERT INTO prices SET purpose=?, cost=?, TLD=?, period=?", array('Transfer', $price['cost'], $tld, 0)); } } } } }