private static function formArrayWalk(array $data, $function, &$success = true, $requiresEmptyPhone = false, $maxPublicity = null) { $phones = array(); if (!is_null($data)) { foreach ($data as $item) { $phone = new Phone($item); $success = !$phone->error && ($phone->format() || $phone->isEmpty()) && $success; if (!$phone->isEmpty()) { // Restrict phone visibility to $maxPublicity if (!is_null($maxPublicity) && Visibility::isLessRestrictive($maxPublicity, $phone->pub)) { $phone->pub = $maxPublicity; } $phones[] = call_user_func(array($phone, $function)); } } } if (count($phones) == 0 && $requiresEmptyPhone) { $phone = new Phone(); if (!is_null($maxPublicity) && Visibility::isLessRestrictive($maxPublicity, $phone->pub)) { // Restrict phone visibility to $maxPublicity $phone->pub = $maxPublicity; } $phones[] = call_user_func(array($phone, $function)); } return $phones; }
#!/usr/bin/php5 <?php require_once 'connect.db.inc.php'; $globals->debug = 0; //do not store backtraces $phones = array('AF' => '93', 'AN' => '599', 'BY' => '375', 'FM' => '691', 'GE' => '995', 'GL' => '299', 'ID' => '62', 'IL' => '972', 'IN' => '91', 'IQ' => '964', 'IR' => '98', 'JO' => '962', 'JP' => '81', 'KG' => '996', 'KW' => '965', 'KZ' => '7', 'LA' => '856', 'LB' => '961', 'LK' => '94', 'MM' => '95', 'MN' => '976', 'MV' => '960', 'MY' => '60', 'NP' => '977', 'OM' => '968', 'PH' => '63', 'PK' => '92', 'QA' => '974', 'SA' => '966', 'SG' => '65', 'SY' => '963', 'TH' => '66', 'TJ' => '992', 'TM' => '993', 'TR' => '90', 'TW' => '886', 'UZ' => '998', 'VG' => '1284', 'VN' => '84', 'YE' => '967'); foreach ($phones as $country => $phone) { XDB::execute('UPDATE geoloc_countries SET phonePrefix = {?} WHERE iso_3166_1_a2 = {?}', $phone, $country); } $res = XDB::iterator('SELECT pid, link_type, link_id, tel_id AS id, search_tel AS search, search_tel AS display FROM profile_phones WHERE search_tel LIKE \'33%\''); while ($item = $res->next()) { $phone = new Phone($item); $phone->format(); XDB::execute('UPDATE profile_phones SET display_tel = {?} WHERE pid = {?} AND link_type = {?} AND link_id = {?} AND tel_id = {?}', $phone->display, $phone->pid(), $phone->linkType(), $phone->linkId(), $phone->id()); } /* vim:set et sw=4 sts=4 ts=4: */
} //allows additionnal spaces and numbers $regexp .= '[0-9 ]*'; //closes parenthesis for ($i = 0; $i < $nbPar; $i++) { $regexp .= ')?'; } $regexp .= '$'; $res = XDB::iterator("SELECT pid, link_type, link_id, tel_id, tel_type, search_tel,\n display_tel, pub, comment\n FROM profile_phones\n WHERE search_tel LIKE {?} AND display_tel NOT REGEXP {?}", $prefix . '%', $regexp); if ($res->numRows() > 0) { //To speed up the update of phone numbers, theses updates are grouped by block of 1000 $values = ''; $i = 0; while ($phone = $res->next()) { $phone = new Phone(array('display' => $phone['display_tel'])); $phone->format(array('format' => $format, 'phoneprf' => $prefix)); if ($values != '') { $values .= ",\n"; } $values .= "('" . addslashes($phone['pid']) . "', '" . addslashes($phone['link_type']) . "', '" . addslashes($phone['link_id']) . "', '" . addslashes($phone['tel_id']) . "', '" . addslashes($phone['tel_type']) . "', '" . addslashes($phone['search_tel']) . "', '" . addslashes($phone->display) . "', '" . addslashes($phone['pub']) . "', '" . addslashes($phone['comment']) . "')"; $i++; if ($i == 1000) { do_update_by_block($values); $values = ''; $i = 0; } } if ($values != '') { do_update_by_block($values); } }
public function __construct($number, $num_type = self::NUM_ANY, $phone_type = self::PHONE_ANY) { $phone = new Phone(array('display' => $number)); $phone->format(); $this->number = $phone->search; $this->num_type = $num_type; $this->phone_type = $phone_type; }