Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2010
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.19 KB | None | 0 0
  1. <?php
  2. class Performance_data_push extends Controller
  3. {
  4.    
  5.     /*
  6.      *
  7.      */
  8.     function console()
  9.     {
  10.         // $data['myError'] = $this->pull_openx_data("host", "user", "pass", "/junk/", $_SERVER['DOCUMENT_ROOT'] . "/junk/", "file.txt");
  11.        
  12.         $data['myError'] = $this->read_openx_data($_SERVER['DOCUMENT_ROOT'] . "/junk/", "file.txt", "pulled_openx_clicks");
  13.        
  14.         /*
  15.         $sql = "LOAD DATA LOCAL INFILE '".$_SERVER['DOCUMENT_ROOT']."/junk/file.txt' INTO TABLE `pulled_openx_clicks`
  16.           FIELDS TERMINATED BY '\\t'
  17.           LINES TERMINATED BY '\\n'
  18.           IGNORE 1 LINES";
  19.         $data['myError'] = $this->db->query($sql);
  20.         */
  21.        
  22.         $data['myVar'] = "Hello World<br />";
  23.        
  24.         $this->load->view('console', $data);
  25.     }
  26.    
  27.     /*
  28.      * Pulls OpenX Data, specified by filename,
  29.      * from specified FTP location with given
  30.      * credentials.
  31.      */
  32.     function pull_openx_data($ftp_host, $ftp_user, $ftp_pass, $remote_path, $local_path, $filename)
  33.     {
  34.         // Load the FTP Library
  35.         $this->load->library('ftp');
  36.        
  37.         // Set the details in the config[] array
  38.         $config['hostname'] = $ftp_host;
  39.         $config['username'] = $ftp_user;
  40.         $config['password'] = $ftp_pass;
  41.         $config['debug']    = TRUE;
  42.        
  43.         // Connect to the FTP
  44.         $this->ftp->connect($config);
  45.        
  46.         // Download the file to the local directory
  47.         // Using the download function in the
  48.         // MY_Ftp.php library file
  49.  
  50.         $rem_path = $remote_path . $filename;
  51.         $loc_path = $local_path . $filename;
  52.        
  53.         if($this->ftp->download($rem_path, $loc_path))
  54.         {
  55.             return TRUE;
  56.         }
  57.         else
  58.         {
  59.             // Send out an E-Mail
  60.             // ** See MY_email_helper.php to change recipient
  61.             $this->load->helper('email');
  62.            
  63.             $error   = $this->ftp->get_error();
  64.             $subject = "Error Pulling OpenX Data";
  65.             $message = "There was an error pulling the OpenX Data from \"{$remote_path}\" to \"{$local_path}\"."
  66.                 . "\n\n\n"
  67.                 . "Data Dump\n\n"
  68.                 . "FTP Host: {$ftp_host}\n"
  69.                 . "FTP User: {$ftp_user}\n"
  70.                 . "FTP Pass: {$ftp_pass}\n"
  71.                 . "Filename: {$filename}\n";
  72.             send_error_email($subject, $message);
  73.            
  74.             show_error("Error downloading {$filename} to {$local_path} from {$remote_path}. With error: {$error}");
  75.         }
  76.        
  77.         // Close the FTP Connection
  78.         $this->ftp->close();
  79.        
  80.     }
  81.    
  82.     /*
  83.      * Takes the file that was pulled to the local server
  84.      * from the remote server via pull_openx_data()
  85.      * and reads it in.
  86.      */
  87.     function read_openx_data($local_path, $filename, $tbl, $delimiter="\t", $terminated="\n", $ignore="1")
  88.     {
  89.        
  90.         // Load Model and assign custom object name
  91.         // Access like: $this->pdp->function()
  92.         $this->load->model('performance_data_push', 'pdp');
  93.  
  94.        
  95.         // Perform the insert
  96.         if($this->pdp->insert_openx_data($local_path, $filename, $tbl, $delimiter, $terminated, $ignore) === TRUE)
  97.         {
  98.             return TRUE;
  99.         }
  100.         else
  101.         {
  102.            
  103.             // Send out an E-Mail
  104.             // ** See MY_email_helper.php to change recipient
  105.             $this->load->helper('email');
  106.            
  107.             $error   = $this->db->_error_message();
  108.             $subject = "Error Inserting OpenX Data";
  109.             $message = "There was an error inersting the OpenX Data into \"{$tbl}\"."
  110.                 . "\n\n\n"
  111.                 . "Data Dump\n\n"
  112.                 . "Local Path: {$local_path}\n"
  113.                 . "Filename: {$filename}\n"
  114.                 . "Table name: {$tbl}\n"
  115.                 . "Delimiter: {$delimiter}\n"
  116.                 . "Terminated At: {$terminated}"
  117.                 . "Lines Ignored: {$ignore}";
  118.                
  119.             send_error_email($subject, $message);
  120.            
  121.             show_error("Error inserting {$filename} into {$tbl} from {$local_path}. With error: {$error}");
  122.            
  123.         }
  124.        
  125.     }
  126.    
  127. }
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. <?php
  156. /*
  157.  * performance_data_push
  158.  * @author Ronald Steelman
  159.  * @filename performance_data_push.php
  160.  * @version 1.0
  161.  * @date Jul 28, 2010
  162.  */
  163.  
  164. class performance_data_push extends Model
  165. {
  166.  
  167.     /*
  168.      * Inserts OpenX data into the database
  169.      */
  170.     function insert_openx_data($local_path, $filename, $tbl, $delimiter="\t", $terminated="\n", $ignore="1")
  171.     {
  172.        
  173.         // Define some variables
  174.         $file = $local_path . $filename;
  175.         $table = $tbl;
  176.        
  177.         $sql = "LOAD DATA LOCAL INFILE '".$_SERVER['DOCUMENT_ROOT']."/junk/file.txt' INTO TABLE `pulled_openx_clicks`
  178.           FIELDS TERMINATED BY '\\t'
  179.           LINES TERMINATED BY '\\n'
  180.           IGNORE 1 LINES";
  181.        
  182.         return $this->db->query($sql);
  183.  
  184.     }
  185.    
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement