public function testUpload() { $test_data = array(array('c1', 'c2'), array('r1c1', 'r1c2')); $test_filename = self::TEST_FILE_PREFIX . date('Y-m-d_H:i'); $test_file = fopen($test_filename, 'w'); foreach ($test_data as $row) { fputcsv($test_file, $row); } fclose($test_file); //upload $silverpop = new \Kiva\Silverpop_Connector\SilverpopFTP(); $result = $silverpop->upload($test_filename); $this->assertTrue($result, "Failed to upload {$test_file} to FTP."); //delete $test_file_pattern = '%' . self::TEST_FILE_PREFIX . '%'; $result = $silverpop->removeMatchingFiles($silverpop::UPLOAD_DIRECTORY, $test_file_pattern); $this->assertGreaterThan(0, $result, "Failed to remove {$test_filename} from FTP."); }
$is_hidden_file = substr($sql_basename, 0, 1) === '.'; if (!$is_hidden_file) { try { $query = file_get_contents(LOCAL_SQL_DIR . '/' . $sql_file); if (empty($sql_files_to_use) || in_array($sql_basename, $sql_files_to_use)) { $filename = getSilverpopFilename($vertex->getEnvironment(), $sql_basename); $local_file = $vertex->exportToCsv(LOCAL_UPLOAD_DIR . '/' . $filename, $query); $upload_files[] = $local_file; } } catch (PDOException $e) { $logger->error("Failed downloading {$sql_file} to local instance. Error: " . print_r($e)); throw new Exception($e); } } } #upload to ftp $silverpop = new \Kiva\Silverpop_Connector\SilverpopFTP(); $silverpop->upload($upload_files); //remove local files foreach (glob(LOCAL_UPLOAD_DIR . "/*") as $file) { unlink($file); } $logger->info('Successfully completed Silverpop Upload job'); #TODO move this function getSilverpopFilename($env_prefix, $basename) { $root_name = $env_prefix . '.' . $basename; $timestamp = date('Y-m-d_H:i'); $destination_file = $root_name . '.' . $timestamp; return $destination_file; }