#!/usr/local/bin/php -q * Copyright 2001-2010 Strangecode, LLC * * This file is part of The Strangecode Codebase. * * The Strangecode Codebase is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * The Strangecode Codebase is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * The Strangecode Codebase. If not, see . */ /** * file_importer.cli.php */ // This file is only an example. // require realpath(dirname(__FILE__) . '/..') . '/config/cli_config.inc.php'; // // $app =& App::getInstance(); // $db =& DB::getInstance(); // // // // Test arguments. // if ($_SERVER['argc'] == 2 && is_dir($_SERVER['argv'][1])) { // $file_dir = preg_replace('/\/$/', '', $_SERVER['argv'][1]); // } else { // die("You must specify the directory of files to import as the only argument.\n"); // } // // // Get array of all files. // $files = getFilesRecursive($file_dir, 1); // // // Loop through files. // // dump($files); // $file_count = 0; // if (is_array($files) && !empty($files)) { // foreach ($files as $file) { // if ($fp = fopen($file, 'r')) { // echo ++$file_count . "\n"; // $file_text = join('', file($file)); // fclose($fp); // // // Do something with file contents. // preg_match('/BALANCE:\s*\$([\.\d]+)/', $file_text, $amt); // $file_date = date('Y-m-d', strtotime(preg_replace('|[^_]*_|', '', basename($file)))); // // $db->query(" // // INSERT INTO invoice_tbl ( // // client_id, // // invoice_type, // // invoice_date, // // invoice_amount, // // invoice_status, // // payment_type, // // invoice_text, // // email_sent_datetime, // // added_datetime // // ) VALUES ( // // '" . $db->escapeString(0) . "', // // '" . $db->escapeString('hosting') . "', // // '" . $db->escapeString($file_date) . "', // // '" . $db->escapeString($amt[1]) . "', // // '" . $db->escapeString('Paid') . "', // // '" . $db->escapeString('') . "', // // '" . $db->escapeString($file_text) . "', // // '" . $db->escapeString($file_date) . "', // // NOW() // // ) // // "); // // } else { // $app->logMsg('Could not open file: ' . $file, LOG_INFO, __FILE__, __LINE__); // } // } // $app->logMsg('Proccessing complete: ' . $file_count . ' files total.', LOG_INFO, __FILE__, __LINE__); // } else { // $app->logMsg('No files available in that directory.', LOG_INFO, __FILE__, __LINE__); // } // // // // // /** // * Find all files in directories recursivly with a specified file extension. // * // * @param string $dir the full path to the directory to scan // * @param array $valid_extensions valid extensions // * @param int $recurs_lev how many levels deep to scan. Set this // * to a low number to prevent infinite loops // * // * @return array multi-dimentional array of found files on success // */ // function getFilesRecursive($dir, $recurs_lev=0, $return=true) // { // static $output; // // $dir_handle = opendir($dir); // while ($dir_handle && ($file = readdir($dir_handle)) !== false) { // if (!preg_match('/^\./', $file)) { // if (is_dir($dir . '/' . $file) && $recurs_lev > 0) { // getFilesRecursive($dir . '/' . $file, $valid_extensions, $recurs_lev - 1); // } else if (!is_dir($dir . '/' . $file)) { // $output[] = $dir . '/' . $file; // } // } // } // if ($return) { // return $output; // } // } // // ?>