public function main() { $aUser = $this->User->find('all'); foreach ($aUser as $user) { $currTime = time(); $lastTime = strtotime(Hash::get($user, 'User.last_update')); //TODO дата с нынешней до last_update //если last_update давнее 12 часов, то брать последние 12 часов $id = $user['User']['id']; $date1 = $lastTime > $currTime - 43200 ? date("Y-m-d H:i:s", $lastTime) : date("Y-m-d H:00:00", $currTime - 43200); $date2 = date("Y-m-d H:i:s"); $data = $this->User->getTimeline($id, $date1, $date2, 0, true); //$this->set('data', $data); //$this->set('timeFrom', strtotime($date1)); //$this->set('timeTo', strtotime($date2)); if (count($data['events'])) { Debugger::dump($user['User']['id'] . ' ' . $user['User']['full_name'] . ' from: ' . $date1 . ' to: ' . $date2); //Debugger::dump($data['events']); /* $Email = new CakeEmail('postmark'); $Email->template('updates_mailer', 'mail')->viewVars( array('data' => $data, 'timeFrom' => strtotime($date1), 'timeTo' => strtotime($date2), 'userID' => $user['User']['id'])) ->to(Hash::get($user, 'User.username')) ->subject('Last updates on Konstruktor.com') ->send(); */ } } }
/** * Debugger::dump shortcut. */ function dump($var) { foreach (func_get_args() as $arg) { Debugger::dump($arg); } return $var; }
public function getPotencialPartner($id = null, $limit) { //Primeiro ve todas as combinações aonde alguem já respondeu alguma coisa a respeito dele e ainda falta a replica $options = []; $ids = []; $waiting = []; $options['fields'] = ['account_id']; $options['conditions'] = ['Relationship.account_id2' => $id, 'Relationship.response2' => null]; $options['recursive'] = -1; $waiting_ids = $this->Account->Relationship->find('all', $options); //Make an array of ids; if (!empty($waiting_ids)) { foreach ($waiting_ids as $row) { $ids[] = $row['Relationship']['account_id']; } } // Debugger::dump($ids); // exit(); $options = []; $total = 0; //Get based on relationship users waiting response $options['recursive'] = -1; if (!empty($ids)) { $options['conditions'] = ['Profile.account_id' => $ids]; $options['limit'] = $limit; $waiting = $this->find('all', $options); $total = count($waiting); } // Debugger::dump($waiting); // exit(); $limit = $limit - $total; if ($limit > 0) { $options['limit'] = $limit; $ids[] = $id; $options['conditions'] = ['Profile.account_id !=' => $ids]; $options['order'] = 'rand()'; $random = $this->find('all', $options); } $result = array_merge($waiting, $random); Debugger::dump($result); exit; return $result; }
<h1>StormDB Testing</h1> <?php require 'localSetup.php'; require __DIR__ . '/../StormDB/StormLoader.php'; $db = new StormDB('google', './../Databases/', 'r+', true); //$db->add(mt_rand()); $collName = 'Users'; if (isset($db->{$collName})) { echo "Collection '" . $collName . "' allready exists."; } else { echo "Collection '" . $collName . "' isn't set. I'm adding it"; $db->add($collName); } $coll = $db->collection($collName); Debugger::dump(array('Collection ' . $collName => $coll)); Debugger::dump(array('Results from coll' => $coll->find())); /* $data = array( 'name' => 'Vojta', 'mail' => '*****@*****.**', 'pass' => 'Strong pass' ); $id[] = $db->collection('collection')->insert($data); $otherData = array( 'surname' => 'Novák', 'telephone' => '908 093 038', 'address' => 'Street 18, London' ); $id[] = $db->collection('collection')->insert($otherData);
public function saveApprovedOrganizations($orgId) { $data = $this->request->data; Debugger::dump($data); if ($data) { $db = $this->Organization->getDataSource(); $db->rawQuery("DELETE FROM approveorgs WHERE organization_id = {$orgId}"); Debugger::dump($data['Approveorg']); foreach ($data['Approveorg'] as $key => $value) { $db->rawQuery("INSERT INTO approveorgs (organization_id, approved_org_id) VALUES({$orgId}, {$value})"); } $this->Session->setFlash('Your organization has been updated.', 'success'); } $this->redirect($this->referer()); }
/** * [doScrapping description] * @param [type] $endpoint [description] * @return [type] [description] */ private function doScrapping($endpoint) { $event = null; $earthquake = null; Debugger::dump('endpoint: ' . $endpoint . ' _' . $_SERVER['HTTP_USER_AGENT']); Debugger::dump('***INICIANDO SCRAPPING****'); $content = $this->scrapper->getContent($endpoint); if (!$content) { Debugger::dump('***ERROR, NO SE OBTUBIERON DATOS'); return; } $this->scrapper->domLoad($content); $tableList = $this->scrapper->findInDom('table tbody tr'); foreach ($tableList as $table) { $earthquakeData = []; foreach ($table->find('td') as $key => $tableItem) { $earthquakeData[$key] = $tableItem->text(); } if (empty($earthquakeData)) { Debugger::dump('***NO HAY DATOS****'); continue; } $dateUTC = $earthquakeData[1]; $dateTs = DatesUtils::toTimestamp($dateUTC); $dateSQL = DatesUtils::toSQLDate($dateUTC); $eventData = ['lat' => $earthquakeData[2], 'lon' => $earthquakeData[3], 'ts' => $dateSQL, 'hash' => md5($dateTs)]; /* Evitar crear eventos duplicados que muestren erroneamente más de un evento siendo que se trata del mismo * pero actualizado. * Esto se hace debido a que el primer informe ante un evento, puede ser preliminar * y se pueden publicar actualizaciones de datos con cambios en magnitud o ubicación geográfica posteriormente. */ $eventExists = $this->Event->checkForExists($eventData, $this->dateBounds); if ($eventExists['exists']) { Debugger::dump('***EVENTO YA EXISTE ****'); $event = $eventExists; } else { Debugger::dump('***NO SE ENCONTRO EVENTO, CREANDO ****'); $this->Event->create(); $event = $this->Event->save($eventData); } if ($event) { $metadatum = ['event_id' => $event['Event']['id'], 'agency_id' => 1, 'lat' => $eventData['lat'], 'lon' => $eventData['lon'], 'ts' => $dateSQL, 'depth' => $earthquakeData[4], 'magnitude' => floatval($earthquakeData[5]), 'geo_reference' => $earthquakeData[6]]; if (!$eventExists['exists']) { Debugger::dump('***EVENTO NO EXISTE, SISMO TAMPOCO ****'); $this->EventMetadatum->create(); $earthquake = $this->EventMetadatum->save($metadatum); } else { $earthquakeExists = $this->EventMetadatum->checkForExists($metadatum, $this->dateBounds, $eventExists['Event']['id']); if ($earthquakeExists['exists']) { Debugger::dump('***EVENTO EXISTE, SISMO TAMBIEN ****'); } else { Debugger::dump('***EVENTO EXISTE, NUEVO SISMO NO. CREANDO NUEVO ASOCIADO A EVENTO****'); $this->EventMetadatum->create(); $earthquake = $this->EventMetadatum->save($metadatum); } } } } return true; }
/** * testDump method * * @return void */ public function testDump() { $var = array('People' => array(array('name' => 'joeseph', 'coat' => 'technicolor', 'hair_color' => 'brown'), array('name' => 'Shaft', 'coat' => 'black', 'hair' => 'black'))); ob_start(); Debugger::dump($var); $result = ob_get_clean(); $open = PHP_SAPI === 'cli' ? "\n" : '<pre>'; $close = PHP_SAPI === 'cli' ? "\n" : '</pre>'; $expected = <<<TEXT {$open}array( 'People' => array( (int) 0 => array( 'name' => 'joeseph', 'coat' => 'technicolor', 'hair_color' => 'brown' ), (int) 1 => array( 'name' => 'Shaft', 'coat' => 'black', 'hair' => 'black' ) ) ){$close} TEXT; $this->assertTextEquals($expected, $result); ob_start(); Debugger::dump($var, 1); $result = ob_get_clean(); $open = PHP_SAPI === 'cli' ? "\n" : '<pre>'; $close = PHP_SAPI === 'cli' ? "\n" : '</pre>'; $expected = <<<TEXT {$open}array( 'People' => array( [maximum depth reached] ) ){$close} TEXT; $this->assertTextEquals($expected, $result); }
/** * [doScrapping description] * @param [type] $endpoint [description] * @return [type] [description] */ private function doScrapping($endpoint) { $event = null; $earthquake = null; Debugger::dump('endpoint: ' . $endpoint . ' _' . $_SERVER['HTTP_USER_AGENT']); Debugger::dump('***INICIANDO SCRAPPING****'); $content = $this->scrapper->getContent($endpoint); $content = json_decode($content); foreach ($content->features as $earthquakeData) { if (empty($earthquakeData)) { Debugger::dump('***NO HAY DATOS****'); continue; } $dateUTC = DatesUtils::toReadableDate($earthquakeData->properties->time / 1000); $dateTs = $earthquakeData->properties->time; $dateSQL = DatesUtils::toSQLDate($dateUTC); $eventData = ['lat' => $earthquakeData->geometry->coordinates[1], 'lon' => $earthquakeData->geometry->coordinates[0], 'ts' => $dateSQL, 'hash' => md5($dateTs)]; /* Evitar crear eventos duplicados que muestren erroneamente más de un evento siendo que se trata del mismo * pero actualizado. * Esto se hace debido a que el primer informe ante un evento, puede ser preliminar * y se pueden publicar actualizaciones de datos con cambios en magnitud o ubicación geográfica posteriormente. */ $eventExists = $this->Event->checkForExists($eventData, $this->dateBounds); if ($eventExists['exists']) { Debugger::dump('***EVENTO YA EXISTE ****'); $event = $eventExists; } else { Debugger::dump('***NO SE ENCONTRO EVENTO, CREANDO ****'); $this->Event->create(); $event = $this->Event->save($eventData); } if ($event) { $metadatum = ['event_id' => $event['Event']['id'], 'agency_id' => 3, 'lat' => $eventData['lat'], 'lon' => $eventData['lon'], 'ts' => $dateSQL, 'depth' => $earthquakeData->geometry->coordinates[2], 'magnitude' => floatval($earthquakeData->properties->mag), 'geo_reference' => $earthquakeData->properties->place, 'magnitude_type' => $earthquakeData->properties->magType]; if (!$eventExists['exists']) { Debugger::dump('***EVENTO NO EXISTE, SISMO TAMPOCO ****'); $this->EventMetadatum->create(); $earthquake = $this->EventMetadatum->save($metadatum); } else { $earthquakeExists = $this->EventMetadatum->checkForExists($metadatum, $this->dateBounds, $eventExists['Event']['id']); if ($earthquakeExists['exists']) { Debugger::dump('***EVENTO EXISTE, SISMO TAMBIEN ****'); } else { Debugger::dump('***EVENTO EXISTE, NUEVO SISMO NO. CREANDO NUEVO ASOCIADO A EVENTO****'); $this->EventMetadatum->create(); $earthquake = $this->EventMetadatum->save($metadatum); } } } } }
/** * testDump method * * @return void */ public function testDump() { $var = array('People' => array(array('name' => 'joeseph', 'coat' => 'technicolor', 'hair_color' => 'brown'), array('name' => 'Shaft', 'coat' => 'black', 'hair' => 'black'))); ob_start(); Debugger::dump($var); $result = ob_get_clean(); $expected = <<<TEXT <pre>array( \t'People' => array( \t\t(int) 0 => array( \t\t), \t\t(int) 1 => array( \t\t) \t) )</pre> TEXT; $this->assertTextEquals($expected, $result); }
public static function dump($var, $label = false, $return = false) { if (DEBUG) { $buffer = ""; if (defined('FIREBUG')) { $buffer .= 'console.group("' . $label . '");' . NL; } else { $buffer .= '<h2>' . $label . '</h2>'; $buffer .= '<table cellpadding="3" cellspacing="0" style="width: 800px; border: 1px solid #ccc">'; } foreach ($var as $key => $value) { if (is_array($value) && isset($value['type']) && isset($value['message'])) { if (defined('FIREBUG')) { $buffer .= 'console.' . $value['type'] . '("' . $value['message'] . '");' . NL; } else { $buffer .= '<tr><td style="border-bottom: 1px dashed #ddd;" valign="top">' . $key . '</td><td style="border-bottom: 1px dashed #ddd;">' . $value['message'] . '</td></tr>'; } } else { if (is_null($value)) { $value = 'null'; } else { if (is_array($value)) { $value = 'array[' . sizeof($value) . '] <br />' . Debugger::dump($value, $key, true); } else { if (is_object($value)) { $value = get_class($value) . ' Object'; } else { if (is_bool($value)) { $value = $value ? 'true' : 'false'; } else { if (is_int($value)) { $value = $value; } } } } } if (defined('FIREBUG')) { $buffer .= 'console.info("' . $key . '=' . $value . '");' . NL; } else { $buffer .= '<tr><td style="border-bottom: 1px dashed #ddd;" valign="top">' . $key . '</td><td style="border-bottom: 1px dashed #ddd;">' . $value . '</td></tr>'; } } } if (defined('FIREBUG')) { $buffer .= 'console.groupEnd();' . NL; } else { $buffer .= '</table>'; } if ($return) { return $buffer; } if (defined('FIREBUG')) { echo '<script type="text/javascript">' . NL . $buffer . '</script>' . NL; } else { echo $buffer; } } }
public function actionContacts($action, $cont_id) { if (MICKA_USER == 'guest') { require PHPINC_DIR . '/templates/403.php'; } $rs = array(); switch ($action) { case 'new': $rs['groups'] = getMsGroups('get_groups'); $rs['data'] = $this->getContacts(-1); break; case 'edit': $rs['groups'] = getMsGroups('get_groups'); $rs['data'] = $this->getContacts($cont_id); break; case 'copy': $record = $this->copyContact($cont_id); if ($record['ok']) { $rs['groups'] = getMsGroups('get_groups'); $rs['data'] = $record['contact']; } else { require PHPINC_DIR . '/templates/404_record.php'; } break; case 'delete': $result = $this->deleteContact($cont_id); Debugger::dump($result); if ($result['ok']) { $redirectUrl = substr(htmlspecialchars($_SERVER['PHP_SELF']), 0, strrpos($_SERVER['PHP_SELF'], '/')) . '?ak=md_contacts'; require PHPPRG_DIR . '/redirect.php'; } else { require PHPINC_DIR . '/templates/404_record.php'; } break; case 'save': $result = $this->setContact($_POST); if ($result['ok']) { $redirectUrl = substr(htmlspecialchars($_SERVER['PHP_SELF']), 0, strrpos($_SERVER['PHP_SELF'], '/')) . '?ak=md_contacts'; require PHPPRG_DIR . '/redirect.php'; } else { require PHPINC_DIR . '/templates/404_record.php'; } break; default: $rs['data'] = $this->getContacts(); } return $rs; }
public function getPanel() { $this->disabled = TRUE; $s = ''; $h = 'htmlSpecialChars'; foreach ($this->queries as $i => $query) { list($sql, $params, $time, $rows, $connection, $source) = $query; $explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS() if ($this->explain && preg_match('#\\s*\\(?\\s*SELECT\\s#iA', $sql)) { try { $cmd = is_string($this->explain) ? $this->explain : 'EXPLAIN'; $explain = $connection->queryArgs("{$cmd} {$sql}", $params)->fetchAll(); } catch (PDOException $e) { } } $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000); if ($explain) { static $counter; $counter++; $s .= "<br /><a href='#' class='nette-toggler' rel='#nette-DbConnectionPanel-row-{$counter}'>explain ►</a>"; } $s .= '</td><td class="nette-DbConnectionPanel-sql">' . DatabaseHelpers::dumpSql(self::$maxLength ? Strings::truncate($sql, self::$maxLength) : $sql); if ($explain) { $s .= "<table id='nette-DbConnectionPanel-row-{$counter}' class='nette-collapsed'><tr>"; foreach ($explain[0] as $col => $foo) { $s .= "<th>{$h($col)}</th>"; } $s .= "</tr>"; foreach ($explain as $row) { $s .= "<tr>"; foreach ($row as $col) { $s .= "<td>{$h($col)}</td>"; } $s .= "</tr>"; } $s .= "</table>"; } if ($source) { $s .= DebugHelpers::editorLink($source[0], $source[1])->class('nette-DbConnectionPanel-source'); } $s .= '</td><td>'; foreach ($params as $param) { $s .= Debugger::dump($param, TRUE); } $s .= '</td><td>' . $rows . '</td></tr>'; } return empty($this->queries) ? '' : '<style> #nette-debug td.nette-DbConnectionPanel-sql { background: white !important } #nette-debug .nette-DbConnectionPanel-source { color: #BBB !important } </style> <h1>Queries: ' . count($this->queries) . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . '</h1> <div class="nette-inner nette-DbConnectionPanel"> <table> <tr><th>Time ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . ' </table> </div>'; }
public function reload($debugMsg = '') { $this->resetData(); $this->load(); Debugger::dump(array('StormDB reloaded ' . $debugMsg => $this)); }
function dump($var) { if (class_exists('Debugger')) { App::import('Core', 'Debugger'); } return Debugger::dump($var); }
public function index() { $this->autoRender = false; $ret = ' '; $aUsers = $this->User->find('all'); //�������� ������ $aUsers = Hash::combine($aUsers, '{n}.User.id', '{n}.User'); //������� ���������� �������� � �������� �������� $aMedia = $this->Media->find('all'); //�������� ������ $aMedia = Hash::combine($aMedia, '{n}.Media.id', '{n}'); //������� ���������� �������� � �������� �������� $aMessages = $this->ChatMessage->find('all'); //�������� ������ $aMessages = Hash::combine($aUsers, '{n}.ChatMessage.id', '{n}'); //������� ���������� �������� � �������� �������� $aRooms = $this->ChatRoom->find('all'); //�������� ������ $aRooms = Hash::combine($aUsers, '{n}.ChatRoom.id', '{n}'); //������� ���������� �������� � �������� �������� // ------------------------------------------------------------------------ // ----------------------------------------------------------- ChatContact CHECK // ------------------------------------------------------------------------ $fulldata = $this->ChatContact->find('all'); $ret .= '<hr>Checking LiveCountry<br>'; $aCountry = $this->Country->find('all'); $aCountry = Hash::combine($aCountry, '{n}.Country.country_code', '{n}'); $fulldata = $this->User->find('all'); $initDate = strtotime(Configure::read('Konstructor.created')); foreach ($fulldata as $entry) { if (!in_array($entry['User']['live_country'], array_keys($aCountry))) { if (!$entry['User']['live_country'] == NULL) { $ret .= ' ' . $entry['User']['id'] . ': has error value in LIVE_COUNTRY: ' . $entry['User']['live_country'] . '<br>'; } } if ($entry['User']['is_admin'] > 0) { $ret .= ' ' . $entry['User']['id'] . ': User\'s "is_admin" field has ' . $entry['User']['is_admin'] . ' value<br>'; } $createDate = strtotime($entry['User']['created']); if ($createDate < $initDate) { $ret .= ' ' . $entry['User']['id'] . ': Incorrect registartion date: ' . date('d-m-Y', $createDate) . ', but need to be less than ' . date('d-m-Y', $initDate) . ' <br>'; } } $ret .= 'done<br><br>'; // -------------------------------------------------------------- // ----------------------------------------- CHAT ROOM USER CHECK // -------------------------------------------------------------- $fulldata = $this->ChatMember->find('all'); $ret .= '<hr>Checking ChatMember<br>'; foreach ($fulldata as $entry) { $recId = $entry['ChatMember']['id']; if (!in_array($entry['ChatMember']['user_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user with "user_id = ' . $entry['ChatMember']['user_id'] . '" does not exist<br>'; } if (!in_array($entry['ChatMember']['room_id'], array_keys($aRooms))) { $ret .= ' ' . $recId . ': room with "room_id = ' . $entry['ChatMember']['room_id'] . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- ChatContact CHECK // ------------------------------------------------------------------------ $fulldata = $this->ChatContact->find('all'); $ret .= '<hr>Checking ChatContact<br>'; foreach ($fulldata as $entry) { $recId = $entry['ChatContact']['id']; if (!in_array($entry['ChatContact']['user_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user with "user_id = ' . $entry['ChatContact']['user_id'] . '" does not exist<br>'; } if (!in_array($entry['ChatContact']['initiator_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user (initiator) with "initiator_id = ' . $entry['ChatContact']['initiator_id'] . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // -------------------------------------------------------------------------- // ----------------------------------------------------------- ChatRoom CHECK // -------------------------------------------------------------------------- $fulldata = $this->ChatRoom->find('all'); $ret .= '<hr>Checking ChatRoom<br>'; foreach ($fulldata as $entry) { $recId = $entry['ChatRoom']['id']; if (!in_array($entry['ChatRoom']['initiator_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user (initiator) with "initiator_id = ' . $entry['ChatRoom']['initiator_id'] . '" does not exist<br>'; } if (!in_array($entry['ChatRoom']['recipient_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user (recipient) with "recipient_id = ' . $entry['ChatRoom']['recipient_id'] . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ---------------------------------------------------------- // ----------------------------------------- CHAT EVENT CHECK // ---------------------------------------------------------- $fulldata = $this->ChatEvent->find('all'); $ret .= '<hr>Checking ChatEvent<br>'; foreach ($fulldata as $entry) { $id = $entry['ChatEvent']['user_id']; $event = $entry['ChatEvent']['event_type']; $recId = $entry['ChatEvent']['id']; if (!in_array($entry['ChatEvent']['event_type'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user with "user_id = ' . $id . '" does not exist<br>'; } $id = $entry['ChatEvent']['initiator_id']; if (!in_array($entry['ChatEvent']['initiator_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': initiator user with "initiator_id = ' . $id . '" does not exist<br>'; } if ($event == 1 || $event == 2 || $event == 4) { $id = $entry['ChatEvent']['msg_id']; if (!in_array($entry['ChatEvent']['msg_id'], array_keys($aMessages))) { $ret .= ' ' . $recId . ': message with "msg_id = ' . $id . '" does not exist<br>'; } } if ($event == 3 || $event == 4) { $id = $entry['ChatEvent']['recipient_id']; if (!$this->User->findById($id)) { $ret .= ' ' . $recId . ': recipient user with "recipient_id = ' . $id . '" does not exist<br>'; } } if ($event == 6 || $event == 7) { $id = $entry['ChatEvent']['file_id']; if (!$this->Media->findById($id)) { $ret .= ' ' . $recId . ': file with "file_id = ' . $id . '" does not exist<br>'; } } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- GROUPS CHECK // ------------------------------------------------------------------------ $fulldata = $this->Group->find('all'); $ret .= '<hr>Checking Groups<br>'; foreach ($fulldata as $entry) { $recId = $entry['Group']['id']; if (!in_array($entry['Group']['owner_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user (owner) with "owner_id = ' . $entry['Group']['owner_id'] . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- GroupVideo CHECK // ------------------------------------------------------------------------ $fulldata = $this->GroupVideo->find('all'); $ret .= '<hr>Checking GroupVideos<br>'; foreach ($fulldata as $entry) { $id = $entry['GroupVideo']['group_id']; $recId = $entry['GroupVideo']['id']; if (!$this->Group->findById($id)) { $ret .= ' ' . $recId . ': group with "group_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- GroupAddress CHECK // ------------------------------------------------------------------------ $fulldata = $this->GroupAddress->find('all'); $ret .= '<hr>Checking GroupAddress<br>'; foreach ($fulldata as $entry) { $id = $entry['GroupAddress']['group_id']; $recId = $entry['GroupAddress']['id']; if (!$this->Group->findById($id)) { $ret .= ' ' . $recId . ': group with "group_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- GroupAchievement CHECK // ------------------------------------------------------------------------ $fulldata = $this->GroupAchievement->find('all'); $ret .= '<hr>Checking GroupAchievement<br>'; foreach ($fulldata as $entry) { $id = $entry['GroupAchievement']['group_id']; $recId = $entry['GroupAchievement']['id']; if (!$this->Group->findById($id)) { $ret .= ' ' . $recId . ': group with "group_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- Order CHECK // ------------------------------------------------------------------------ $fulldata = $this->Order->find('all'); $ret .= '<hr>Checking Order<br>'; foreach ($fulldata as $entry) { $id = $entry['Order']['contractor_id']; $recId = $entry['Order']['id']; if (!$this->Contractor->findById($id)) { $ret .= ' ' . $recId . ': contractor with "contractor_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- Product CHECK // ------------------------------------------------------------------------ $fulldata = $this->Product->find('all'); $ret .= '<hr>Checking Product<br>'; foreach ($fulldata as $entry) { $id = $entry['Product']['product_type_id']; $recId = $entry['Product']['id']; if (!$this->ProductType->findById($id)) { $ret .= ' ' . $recId . ': product type with "product_type_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- OrderProduct CHECK // ------------------------------------------------------------------------ $fulldata = $this->OrderProduct->find('all'); $ret .= '<hr>Checking OrderProduct<br>'; foreach ($fulldata as $entry) { $id = $entry['OrderProduct']['order_id']; $recId = $entry['OrderProduct']['id']; if (!$this->Order->findById($id)) { $ret .= ' ' . $recId . ': order with "order_id = ' . $id . '" does not exist<br>'; } $id = $entry['OrderProduct']['product_id']; if (!$this->Product->findById($id)) { $ret .= ' ' . $recId . ': product with "product_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- OrderType CHECK // ------------------------------------------------------------------------ $fulldata = $this->OrderType->find('all'); $ret .= '<hr>Checking OrderType<br>'; foreach ($fulldata as $entry) { $id = $entry['OrderType']['order_id']; $recId = $entry['OrderType']['id']; if (!$this->Order->findById($id)) { $ret .= ' ' . $recId . ': order with "order_id = ' . $id . '" does not exist<br>'; } $id = $entry['OrderType']['product_type_id']; if (!$this->ProductType->findById($id)) { $ret .= ' ' . $recId . ': product type with "product_type_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- Product CHECK // ------------------------------------------------------------------------ $fulldata = $this->Product->find('all'); $ret .= '<hr>Checking Product<br>'; foreach ($fulldata as $entry) { $id = $entry['Product']['product_type_id']; $recId = $entry['Product']['id']; if (!$this->ProductType->findById($id)) { $ret .= ' ' . $recId . ': product type with "product_type_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------- // ----------------------------------------------------------- Project CHECK // ------------------------------------------------------------------------- $fulldata = $this->Project->find('all'); $ret .= '<hr>Checking Project<br>'; foreach ($fulldata as $entry) { $id = $entry['Project']['group_id']; $recId = $entry['Project']['id']; if (!$this->Group->findById($id)) { $ret .= ' ' . $recId . ': group with "group_id = ' . $id . '" does not exist<br>'; } if (!in_array($entry['Project']['owner_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': owner (user) with "owner_id = ' . $entry['Project']['owner_id'] . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- ProjectEvent CHECK // ------------------------------------------------------------------------ $fulldata = $this->ProjectEvent->find('all'); $ret .= '<hr>Checking ProjectEvent<br>'; foreach ($fulldata as $entry) { $recId = $entry['ProjectEvent']['id']; if (!in_array($entry['ProjectEvent']['user_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': owner (user) with "owner_id = ' . $entry['ProjectEvent']['user_id'] . '" does not exist<br>'; } $id = $entry['ProjectEvent']['project_id']; if (!$this->Project->findById($id)) { $ret .= ' ' . $recId . ': project with "project_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- ProjectEvent CHECK // ------------------------------------------------------------------------ $fulldata = $this->ProjectEvent->find('all'); $ret .= '<hr>Checking ProjectEvent<br>'; foreach ($fulldata as $entry) { $id = $entry['ProjectEvent']['project_id']; $recId = $entry['ProjectEvent']['id']; if (!$this->Project->findById($id)) { $ret .= ' ' . $recId . ': project with "project_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- ProjectMember CHECK // ------------------------------------------------------------------------ $fulldata = $this->ProjectMember->find('all'); $ret .= '<hr>Checking ProjectMember<br>'; foreach ($fulldata as $entry) { $id = $entry['ProjectMember']['project_id']; $recId = $entry['ProjectMember']['id']; if (!$this->Project->findById($id)) { $ret .= ' ' . $recId . ': project with "project_id = ' . $id . '" does not exist<br>'; } if (!in_array($entry['ProjectMember']['user_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': project with "project_id = ' . $entry['ProjectMember']['user_id'] . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ------------------------------------------------------------------------ // ----------------------------------------------------------- Subproject CHECK // ------------------------------------------------------------------------ $fulldata = $this->Subproject->find('all'); $ret .= '<hr>Checking Subproject<br>'; foreach ($fulldata as $entry) { $id = $entry['Subproject']['project_id']; $recId = $entry['Subproject']['id']; if (!$this->Project->findById($id)) { $ret .= ' ' . $recId . ': project with "project_id = ' . $id . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ---------------------------------------------------------------------------- // ----------------------------------------------------------- Task CHECK // ---------------------------------------------------------------------------- $fulldata = $this->Task->find('all'); $ret .= '<hr>Checking Task<br>'; foreach ($fulldata as $entry) { $id = $entry['Task']['subproject_id']; $recId = $entry['Task']['id']; if (!$this->Subproject->findById($id)) { $ret .= ' ' . $recId . ': project with "project_id = ' . $id . '" does not exist<br>'; } if (!in_array($entry['Task']['manager_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user (manager) with "manager_id = ' . $entry['Task']['manager_id'] . '" does not exist<br>'; } if (!in_array($entry['Task']['creator_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user (creator) with "creator_id = ' . $entry['Task']['creator_id'] . '" does not exist<br>'; } if (!in_array($entry['Task']['user_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user with "user_id = ' . $entry['Task']['user_id'] . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ---------------------------------------------------------------------------- // ----------------------------------------------------------- UserAchievement CHECK // ---------------------------------------------------------------------------- $fulldata = $this->UserAchievement->find('all'); $ret .= '<hr>Checking UserAchievement<br>'; foreach ($fulldata as $entry) { $recId = $entry['UserAchievement']['id']; if (!in_array($entry['UserAchievement']['user_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user with "user_id = ' . $entry['UserAchievement']['user_id'] . '" does not exist<br>'; } } $ret .= 'done<br><br>'; // ---------------------------------------------------------------------------- // ----------------------------------------------------------- UserEvent CHECK // ---------------------------------------------------------------------------- $fulldata = $this->UserEvent->find('all'); $ret .= '<hr>Checking UserEvent<br>'; foreach ($fulldata as $entry) { $recId = $entry['UserEvent']['id']; if (!in_array($entry['UserEvent']['user_id'], array_keys($aUsers))) { $ret .= ' ' . $recId . ': user with "user_id = ' . $entry['UserEvent']['user_id'] . '" does not exist<br>'; } } $ret .= 'done<br><br>'; Debugger::dump($ret); }
/** * testDump method * * @return void */ public function testDump() { $var = array('People' => array(array('name' => 'joeseph', 'coat' => 'technicolor', 'hair_color' => 'brown'), array('name' => 'Shaft', 'coat' => 'black', 'hair' => 'black'))); ob_start(); Debugger::dump($var); $result = ob_get_clean(); $open = php_sapi_name() == 'cli' ? "\n" : '<pre>'; $close = php_sapi_name() == 'cli' ? "\n" : '</pre>'; $expected = <<<TEXT {$open}array( \t'People' => array( \t\t(int) 0 => array( \t\t\t'name' => 'joeseph', \t\t\t'coat' => 'technicolor', \t\t\t'hair_color' => 'brown' \t\t), \t\t(int) 1 => array( \t\t\t'name' => 'Shaft', \t\t\t'coat' => 'black', \t\t\t'hair' => 'black' \t\t) \t) ){$close} TEXT; $this->assertTextEquals($expected, $result); }
/** * Quickly dump a $var * * @param mixed $var * @return void */ function dump($var) { if (!class_exists('Debugger')) { App::uses('Debugger', 'Utility'); } return Debugger::dump($var); }
/** * [doScrapping description] * @param [type] $endpoint [description] * @return [type] [description] */ private function doScrapping($endpoint) { $event = null; $earthquake = null; $i = 0; Debugger::dump('endpoint: ' . $endpoint . ' _' . $_SERVER['HTTP_USER_AGENT']); Debugger::dump('***INICIANDO SCRAPPING****'); $content = $this->scrapper->getContent($endpoint); if ($content) { $this->scrapper->domLoad($content); $tableList = $this->scrapper->findInDom('table tbody tr'); } else { Debugger::dump('***ERROR, NO SE OBTUBIERON DATOS'); } //get each table node foreach ($tableList as $tableKey => $table) { $earthquakeData = array(); //get each data item $i = 0; foreach ($table->find('td') as $itemKey => $tableItem) { $earthquakeData[$itemKey] = $tableItem->text(); $i++; } if ($i < 8 or empty($earthquakeData)) { continue; } $latDMSArr = Coordinates::extractDMS($earthquakeData[2]); $lonDMSArr = Coordinates::extractDMS($earthquakeData[3]); $lat = Coordinates::DMStoDEC($latDMSArr['coordinates'][0], $latDMSArr['coordinates'][1], 0, $latDMSArr['geoDir']); $lon = Coordinates::DMStoDEC($lonDMSArr['coordinates'][0], $lonDMSArr['coordinates'][1], 0, $lonDMSArr['geoDir']); $dateUTC = $earthquakeData[0]; $dateTs = DatesUtils::toTimestamp($dateUTC); $dateSQL = DatesUtils::toSQLDate($dateUTC); $eventData = array('lat' => $lat, 'lon' => $lon, 'ts' => $dateSQL, 'hash' => md5($dateTs)); /* Evitar crear eventos duplicados que muestren erroneamente más de un evento siendo que se trata del mismo * pero actualizado. * Esto se hace debido a que el primer informe ante un evento, puede ser preliminar * y se pueden publicar actualizaciones de datos con cambios en magnitud o ubicación geográfica posteriormente. */ $eventExists = $this->Event->checkForExists($eventData, $this->dateBounds); if ($eventExists['exists']) { Debugger::dump('***EVENTO YA EXISTE ****'); //echo ('evento ya existe <br>'); $event = $eventExists; } else { Debugger::dump('***NO SE ENCONTRO EVENTO, CREANDO ****'); $this->Event->create(); $event = $this->Event->save($eventData); } if ($event) { $metadatum = array('event_id' => $event['Event']['id'], 'agency_id' => 2, 'lat' => $eventData['lat'], 'lon' => $eventData['lon'], 'ts' => $dateSQL, 'depth' => $earthquakeData[4], 'magnitude' => floatval($earthquakeData[1]), 'geo_reference' => $earthquakeData[7], 'magnitude_type' => $earthquakeData[1] > 3.5 ? 'Mw' : 'Ml'); if (!$eventExists['exists']) { Debugger::dump('***SISMO NO EXISTE, CREANDO ****'); $this->EventMetadatum->create(); $earthquake = $this->EventMetadatum->save($metadatum); } else { $earthquakeExists = $this->EventMetadatum->checkForExists($metadatum, $this->dateBounds, $eventExists['Event']['id']); if ($earthquakeExists['exists']) { Debugger::dump('***EVENTO EXISTE, SISMO TAMBIEN ****'); } else { Debugger::dump('***EVENTO EXISTE, NUEVO SISMO NO. CREANDO NUEVO ASOCIADO A EVENTO****'); $this->EventMetadatum->create(); $earthquake = $this->EventMetadatum->save($metadatum); } } } } }
/** * testDump method * * @return void */ public function testDump() { $var = array('People' => array(array('name' => 'joeseph', 'coat' => 'technicolor', 'hair_color' => 'brown'), array('name' => 'Shaft', 'coat' => 'black', 'hair' => 'black'))); ob_start(); Debugger::dump($var); $result = ob_get_clean(); $expected = "<pre>array(\n\t\"People\" => array()\n)</pre>"; $this->assertEquals($expected, $result); }
public function edit($id = null) { if (!$id) { throw new NotFoundException('Invalid user'); } $user = $this->User->findById($id); if (!$user) { throw new NotFoundException('Invalid user'); } if ($this->request->is('post') || $this->request->is('put')) { $this->User->id = $id; Debugger::dump($this->request->data); if ($this->User->saveAll($this->request->data)) { $this->Session->setFlash('Your profile has been updated.', 'success'); $this->redirect(array('action' => 'profile', $id)); } else { $this->Session->setFlash('Unable to update your profile.'); } } if (!$this->request->data) { $this->request->data = $user; } $this->_setStateDropDown(); $interests = $this->Interest->find('list', array('fields' => array('Interest.id', 'Interest.interests'))); $this->set(compact('interests')); }