News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1232831826:v:use_geshi-1:v:type-php

Started by SleePy, Jan 24, 2009, 09:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SleePy

// Remove the short joins
function convert_update_short_join()
{
   global $files, $path;

   // Now we loop through all file and do a strtr fix.
   $replaces = array();
   foreach ($files as $file)
   {
      // Get the contents of the file.
      $file_contents = file_get_contents($path . '/' . $file);

      // Try to find any short joins.
      preg_match_all('~(\t)*FROM \(([^\)]+)\)~is', $file_contents, $matches);

      // Lets loop trhough all the matches.
      foreach ($matches[2] as $key => $string)
      {
         // Explode the short join.
         $temp = explode(', ', $string);

         // Start off the new string with some padding (maybe).
         $newstring = $matches[1][$key] . 'FROM ' . $temp[0];
         unset($temp[0]);

         // Now all others we will inner join.
         foreach ($temp as $str)
            $newstring .= "\n" . $matches[1][$key] . '   INNER JOIN ' . $str;

         // Now get it ready to go out.
         $replaces[$matches[0][$key]] = $newstring;
      }
   }

   // Now do updates to all files.
   DoUpdates('strtr', $replaces);
}
No siggy! :D