/** * Import movies */ public function actionImport() { if ($movies = CHttpRequest::getPost('movies', false)) { foreach (explode("\n", $movies) as $key => $movie) { if (!ImportLog::model()->find('import_name=:movie', array(':movie' => $movie))) { if (substr($movie, -2) == 02) { continue; } // 2nd part $search = SearchController::search(str_replace(array('-', '01'), ' ', $movie)); $log = new ImportLog(); $log->import_name = $movie; $log->search_id = $search->id; $log->save(); } } } $this->render('import', array('imported_movies' => ImportLog::model()->findAll())); }
public function saveLogAndExit($reportLayout = NULL, $txtFile = NULL, $success = FALSE) { //First, delete any preexisting Failured records, these shouldn't be needed/interesting after this. $this->log("Cleaning up prior failed import logs...."); $this->getPublisherOrPlatform->removeFailedSushiImports; if (!$txtFile) { $txtFile = strtotime("now") . '.txt'; } $logFileLocation = 'logs/' . $txtFile; $this->log("Log File Name: {$logFileLocation}"); if ($success) { $this->logStatus("Finished processing " . $this->getServiceProvider . ": {$reportLayout}."); } //save the actual log file $fp = fopen(BASE_DIR . $logFileLocation, 'w'); fwrite($fp, implode("\n", $this->detailLog)); fclose($fp); //save to import log!! $importLog = new ImportLog(); $importLog->loginID = "sushi"; $importLog->layoutCode = $reportLayout; $importLog->fileName = 'archive/' . $txtFile; $importLog->archiveFileURL = 'archive/' . $txtFile; $importLog->logFileURL = $logFileLocation; $importLog->details = implode("<br />", $this->statusLog); try { $importLog->save(); $importLogID = $importLog->primaryKey; } catch (Exception $e) { echo $e->getMessage(); } $importLogPlatformLink = new ImportLogPlatformLink(); $importLogPlatformLink->importLogID = $importLogID; $importLogPlatformLink->platformID = $this->platformID; try { $importLogPlatformLink->save(); } catch (Exception $e) { echo $e->getMessage(); } if (!$success) { throw new Exception(implode("\n", $this->detailLog)); } }
$importLog = new ImportLog(new NamedArguments(array('primaryKey' => $importLogID))); $importLog->fileName = $importLog->fileName; $importLog->archiveFileURL = $importLog->fileName; $importLog->details = $importLog->details . "\n" . $rownumber . _(" titles processed.") . $logSummary; } else { $importLog = new ImportLog(); $importLog->importLogID = ''; $importLog->fileName = $orgFileName; $importLog->archiveFileURL = 'archive/' . $uploadedFilename; $importLog->details = $rownumber . _(" titles processed.") . $logSummary; } $importLog->loginID = $user->loginID; $importLog->layoutCode = $layoutCode; $importLog->logFileURL = $logfile; try { $importLog->save(); $importLogID = $importLog->primaryKey; } catch (Exception $e) { echo $e->getMessage(); } //only get unique platforms $platformArray = array_unique($platformArray, SORT_REGULAR); foreach ($platformArray as $platformID) { $importLogPlatformLink = new ImportLogPlatformLink(); $importLogPlatformLink->importLogID = $importLogID; $importLogPlatformLink->platformID = $platformID; try { $importLogPlatformLink->save(); } catch (Exception $e) { echo $e->getMessage(); }