Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Performance_data_push extends Controller
- {
- /*
- *
- */
- function console()
- {
- // $data['myError'] = $this->pull_openx_data("host", "user", "pass", "/junk/", $_SERVER['DOCUMENT_ROOT'] . "/junk/", "file.txt");
- $data['myError'] = $this->read_openx_data($_SERVER['DOCUMENT_ROOT'] . "/junk/", "file.txt", "pulled_openx_clicks");
- /*
- $sql = "LOAD DATA LOCAL INFILE '".$_SERVER['DOCUMENT_ROOT']."/junk/file.txt' INTO TABLE `pulled_openx_clicks`
- FIELDS TERMINATED BY '\\t'
- LINES TERMINATED BY '\\n'
- IGNORE 1 LINES";
- $data['myError'] = $this->db->query($sql);
- */
- $data['myVar'] = "Hello World<br />";
- $this->load->view('console', $data);
- }
- /*
- * Pulls OpenX Data, specified by filename,
- * from specified FTP location with given
- * credentials.
- */
- function pull_openx_data($ftp_host, $ftp_user, $ftp_pass, $remote_path, $local_path, $filename)
- {
- // Load the FTP Library
- $this->load->library('ftp');
- // Set the details in the config[] array
- $config['hostname'] = $ftp_host;
- $config['username'] = $ftp_user;
- $config['password'] = $ftp_pass;
- $config['debug'] = TRUE;
- // Connect to the FTP
- $this->ftp->connect($config);
- // Download the file to the local directory
- // Using the download function in the
- // MY_Ftp.php library file
- $rem_path = $remote_path . $filename;
- $loc_path = $local_path . $filename;
- if($this->ftp->download($rem_path, $loc_path))
- {
- return TRUE;
- }
- else
- {
- // Send out an E-Mail
- // ** See MY_email_helper.php to change recipient
- $this->load->helper('email');
- $error = $this->ftp->get_error();
- $subject = "Error Pulling OpenX Data";
- $message = "There was an error pulling the OpenX Data from \"{$remote_path}\" to \"{$local_path}\"."
- . "\n\n\n"
- . "Data Dump\n\n"
- . "FTP Host: {$ftp_host}\n"
- . "FTP User: {$ftp_user}\n"
- . "FTP Pass: {$ftp_pass}\n"
- . "Filename: {$filename}\n";
- send_error_email($subject, $message);
- show_error("Error downloading {$filename} to {$local_path} from {$remote_path}. With error: {$error}");
- }
- // Close the FTP Connection
- $this->ftp->close();
- }
- /*
- * Takes the file that was pulled to the local server
- * from the remote server via pull_openx_data()
- * and reads it in.
- */
- function read_openx_data($local_path, $filename, $tbl, $delimiter="\t", $terminated="\n", $ignore="1")
- {
- // Load Model and assign custom object name
- // Access like: $this->pdp->function()
- $this->load->model('performance_data_push', 'pdp');
- // Perform the insert
- if($this->pdp->insert_openx_data($local_path, $filename, $tbl, $delimiter, $terminated, $ignore) === TRUE)
- {
- return TRUE;
- }
- else
- {
- // Send out an E-Mail
- // ** See MY_email_helper.php to change recipient
- $this->load->helper('email');
- $error = $this->db->_error_message();
- $subject = "Error Inserting OpenX Data";
- $message = "There was an error inersting the OpenX Data into \"{$tbl}\"."
- . "\n\n\n"
- . "Data Dump\n\n"
- . "Local Path: {$local_path}\n"
- . "Filename: {$filename}\n"
- . "Table name: {$tbl}\n"
- . "Delimiter: {$delimiter}\n"
- . "Terminated At: {$terminated}"
- . "Lines Ignored: {$ignore}";
- send_error_email($subject, $message);
- show_error("Error inserting {$filename} into {$tbl} from {$local_path}. With error: {$error}");
- }
- }
- }
- <?php
- /*
- * performance_data_push
- * @author Ronald Steelman
- * @filename performance_data_push.php
- * @version 1.0
- * @date Jul 28, 2010
- */
- class performance_data_push extends Model
- {
- /*
- * Inserts OpenX data into the database
- */
- function insert_openx_data($local_path, $filename, $tbl, $delimiter="\t", $terminated="\n", $ignore="1")
- {
- // Define some variables
- $file = $local_path . $filename;
- $table = $tbl;
- $sql = "LOAD DATA LOCAL INFILE '".$_SERVER['DOCUMENT_ROOT']."/junk/file.txt' INTO TABLE `pulled_openx_clicks`
- FIELDS TERMINATED BY '\\t'
- LINES TERMINATED BY '\\n'
- IGNORE 1 LINES";
- return $this->db->query($sql);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement