/** * @param type $addr * @throws AppException */ public function fromBlock($addr) { if (!is_scalar($addr)) { throw new Exception('Location address is not valid.'); } $block = LocationBlock::find()->where(':addr BETWEEN start AND end', [':addr' => ip2long($addr)])->one(); if ($block !== null) { $this->andWhere('id = :id', [':id' => $block->id]); } else { $this->andWhere(0); } return $this; }
public function down() { $this->dropTable(LocationBlock::tableName()); }
public function applyBlockCsv($file) { $columns = ['id', 'start', 'end']; $update = ['id', 'start']; $rows = []; if (($handle = fopen($file, 'r')) !== false) { while (($data = fgetcsv($handle, 1000, ',')) !== false) { if (!isset($data[2]) || intval($data[2]) === 0) { continue; } $rows[] = [(int) $data[2], (int) $data[0], (int) $data[1]]; if (count($rows) === $this->maxExecuteRows) { $this->batchInsertDuplicate(LocationBlock::tableName(), $columns, $rows, $update)->execute(); $rows = []; } } if (count($rows) > 0) { $this->batchInsertDuplicate(LocationBlock::tableName(), $columns, $rows, $update)->execute(); } fclose($handle); } }