public function actionNumbers() { if ($this->deleteReports) { $this->cleanCollection(Report::collectionName()); $this->cleanCollection(ReportItem::collectionName()); } $this->actionOperators(); $query = (new Query())->from($this->numberTableName); $this->stdout("Загружаю номера\n", Console::FG_BLUE, Console::BOLD); $this->stdout("Источник: таблица '{$this->numberTableName}' " . $query->count() . " записей.\nЦелевая коллекция: '" . Number::collectionName() . "'\n"); $this->cleanCollection(Number::collectionName()); $count = 0; foreach ($query->all() as $item) { $number = new Number(['number' => $item['number']]); $number->ownerId = (int) $item['owner_id']; $number->operatorId = $this->operatorJunction[$item['operator_id']]; $number->destination = $item['type'] == '1' ? Number::DESTINATION_PHONE : Number::DESTINATION_MODEM; $number->limit = $item['limit'] == '0' || $item['limit'] === null ? null : (int) $item['limit']; $options = []; if ($item['rent_date'] === null && $number->limit === null) { $options[] = Number::OPTION_TRIP; } if ($number->limit !== null && $item['accounting'] == '1') { $options[] = Number::OPTION_ACCOUNTING; } $number->options = $options; $history = []; if ($item['rent_date'] !== null && $item['owner_id'] !== null) { $history[] = ['rentDate' => new MongoDate((int) $item['rent_date']), 'ownerId' => (int) $item['owner_id']]; } $number->history = $history; $number->comment = $item['comment']; if ($number->save(false)) { $count++; } } $this->stdout("Успешно загружено {$count} записей\n", Console::BOLD, Console::FG_GREEN); $this->stdout("\n"); $this->actionDocuments(); return Controller::EXIT_CODE_NORMAL; }