SQL INSERT Issue

  1. /**
  2.  * create_process_status
  3.  * Description: Creates a record for FID in media_process_status table
  4.  * @param  $fid, $type
  5.  */
  6. function create_process_status($fid, $type) {
  7.         //Query setup and execute
  8.        
  9.         $result = db_query("INSERT INTO {media_process_status} (fid, type) VALUES (%d, %d)", $fid, $type);
  10.        
  11.         //If fail - watchdog notify
  12.         if (!$result) {
  13.                  watchdog('media_process', t("media_process: couldn't insert a record into media_process_table for fileid $fid"), WATCHDOG_WARNING);
  14.         }
  15.        
  16.         //Return Result
  17.         return $result;
  18. }
  19.  
  20.  
  21. //AND IT GETS CALLED BY detect_handler() function
  22.  
  23.  
  24. /**
  25.  * Detects que files, sort types, and handles
  26.  * @param
  27.  * @return
  28.  *              Returns Null if there was no job to be processed. False if process fails.
  29.  */
  30. function detect_handler() {
  31.        
  32.         //Narrow List of files to be processed - By Files & media_process_status tables comparisson, Order list by filemime
  33.         //Query setup
  34.         $node_type_allow = "'submission', 'submission_ar'"; //@todo get it from the front-end admin
  35.        
  36.         $query_filter  = "SELECT node.nid, node.vid, files.filename, files.filemime, files.fid, files.filepath FROM node, files WHERE  blah blah";     
  37.        
  38.         $result_filter = db_query($query_filter); //Grab result
  39.        
  40.         //Loop through records of the result
  41.         while ($files = db_fetch_array($result_filter)) {
  42.                
  43.                 //Setup Vars
  44.                 $filemime = $files["filemime"];
  45.                 $filename = $files["filename"];
  46.                 $filepath = $files["filepath"];
  47.                 $fid      = (int) $files["fid"];
  48.                 $vid      = (int) $files["vid"];
  49.                 $nid      = (int) $files["nid"];
  50.        
  51.                 $basepath = exec('pwd');                                                                                                //Grab the current location by executing pwd on system level
  52.                 $location = $basepath . "/" . file_directory_path()  .'/';                              //Setup the Location
  53.        
  54.                 //Check if file exists in Files folder
  55.             $filecheck_status = media_process_filecheck($filename, $location)
  56.            
  57.             if ($filecheck_status == TRUE) {
  58.                 var_dump("found");
  59.                         //Call function CheckfileType() passing filemime type and filename to find out if image or video
  60.                         $type = CheckfileType($filemime, $filename);
  61.                
  62.                         //Create a record for it on update_status
  63.                         $result_create = create_process_status($fid, $type);
  64.        
  65.                         //During the loop, if the file type is Image -- pass @param fid, nid, vid, filename to process_image()
  66.                         if ($type == 1) {
  67.                                 $pimage_result = process_image($fid, $nid, $vid, $filename);
  68.                                
  69.                         //If the file type is Video -- pass $param fid, nid, filename to process_video()
  70.                         } else if ($type == 0) {
  71.                                 $pimage_result = process_video($fid, $nid, $vid, $filename);
  72.                        
  73.                         //Else return null
  74.                         } else {
  75.                                 $status = 3;
  76.                         }
  77.                
  78.                
  79.                 } else {
  80.                         watchdog('media_process', t("media_process: Filename $filename could not be found -- skipped the process"), WATCHDOG_WARNING);
  81.                 }
  82.                
  83.         }
  84.        
  85.         return
  86. }