[1] | 1 | #!/usr/local/bin/php -q |
---|
| 2 | <?php |
---|
| 3 | /** |
---|
[362] | 4 | * The Strangecode Codebase - a general application development framework for PHP |
---|
| 5 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
[376] | 6 | * Copyright 2001-2010 Strangecode, LLC |
---|
[362] | 7 | * |
---|
| 8 | * This file is part of The Strangecode Codebase. |
---|
| 9 | * |
---|
| 10 | * The Strangecode Codebase is free software: you can redistribute it and/or |
---|
| 11 | * modify it under the terms of the GNU General Public License as published by the |
---|
| 12 | * Free Software Foundation, either version 3 of the License, or (at your option) |
---|
| 13 | * any later version. |
---|
| 14 | * |
---|
| 15 | * The Strangecode Codebase is distributed in the hope that it will be useful, but |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 18 | * details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License along with |
---|
| 21 | * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | /** |
---|
[1] | 25 | * file_importer.cli.php |
---|
| 26 | */ |
---|
| 27 | |
---|
[171] | 28 | // This file is only an example. |
---|
[1] | 29 | |
---|
[136] | 30 | |
---|
[171] | 31 | // require realpath(dirname(__FILE__) . '/..') . '/config/cli_config.inc.php'; |
---|
| 32 | // |
---|
| 33 | // $app =& App::getInstance(); |
---|
| 34 | // $db =& DB::getInstance(); |
---|
| 35 | // |
---|
| 36 | // |
---|
| 37 | // // Test arguments. |
---|
| 38 | // if ($_SERVER['argc'] == 2 && is_dir($_SERVER['argv'][1])) { |
---|
| 39 | // $file_dir = preg_replace('/\/$/', '', $_SERVER['argv'][1]); |
---|
| 40 | // } else { |
---|
| 41 | // die("You must specify the directory of files to import as the only argument.\n"); |
---|
| 42 | // } |
---|
| 43 | // |
---|
| 44 | // // Get array of all files. |
---|
| 45 | // $files = getFilesRecursive($file_dir, 1); |
---|
| 46 | // |
---|
| 47 | // // Loop through files. |
---|
| 48 | // // dump($files); |
---|
| 49 | // $file_count = 0; |
---|
| 50 | // if (is_array($files) && !empty($files)) { |
---|
| 51 | // foreach ($files as $file) { |
---|
| 52 | // if ($fp = fopen($file, 'r')) { |
---|
| 53 | // echo ++$file_count . "\n"; |
---|
| 54 | // $file_text = join('', file($file)); |
---|
| 55 | // fclose($fp); |
---|
| 56 | // |
---|
| 57 | // // Do something with file contents. |
---|
| 58 | // preg_match('/BALANCE:\s*\$([\.\d]+)/', $file_text, $amt); |
---|
| 59 | // $file_date = date('Y-m-d', strtotime(preg_replace('|[^_]*_|', '', basename($file)))); |
---|
| 60 | // // $db->query(" |
---|
| 61 | // // INSERT INTO invoice_tbl ( |
---|
| 62 | // // client_id, |
---|
| 63 | // // invoice_type, |
---|
| 64 | // // invoice_date, |
---|
| 65 | // // invoice_amount, |
---|
| 66 | // // invoice_status, |
---|
| 67 | // // payment_type, |
---|
| 68 | // // invoice_text, |
---|
| 69 | // // email_sent_datetime, |
---|
| 70 | // // added_datetime |
---|
| 71 | // // ) VALUES ( |
---|
| 72 | // // '" . $db->escapeString(0) . "', |
---|
| 73 | // // '" . $db->escapeString('hosting') . "', |
---|
| 74 | // // '" . $db->escapeString($file_date) . "', |
---|
| 75 | // // '" . $db->escapeString($amt[1]) . "', |
---|
| 76 | // // '" . $db->escapeString('Paid') . "', |
---|
| 77 | // // '" . $db->escapeString('') . "', |
---|
| 78 | // // '" . $db->escapeString($file_text) . "', |
---|
| 79 | // // '" . $db->escapeString($file_date) . "', |
---|
| 80 | // // NOW() |
---|
| 81 | // // ) |
---|
| 82 | // // "); |
---|
| 83 | // |
---|
| 84 | // } else { |
---|
| 85 | // $app->logMsg('Could not open file: ' . $file, LOG_INFO, __FILE__, __LINE__); |
---|
| 86 | // } |
---|
| 87 | // } |
---|
| 88 | // $app->logMsg('Proccessing complete: ' . $file_count . ' files total.', LOG_INFO, __FILE__, __LINE__); |
---|
| 89 | // } else { |
---|
| 90 | // $app->logMsg('No files available in that directory.', LOG_INFO, __FILE__, __LINE__); |
---|
| 91 | // } |
---|
| 92 | // |
---|
| 93 | // |
---|
| 94 | // |
---|
| 95 | // |
---|
| 96 | // /** |
---|
| 97 | // * Find all files in directories recursivly with a specified file extension. |
---|
| 98 | // * |
---|
| 99 | // * @param string $dir the full path to the directory to scan |
---|
| 100 | // * @param array $valid_extensions valid extensions |
---|
| 101 | // * @param int $recurs_lev how many levels deep to scan. Set this |
---|
| 102 | // * to a low number to prevent infinite loops |
---|
| 103 | // * |
---|
| 104 | // * @return array multi-dimentional array of found files on success |
---|
| 105 | // */ |
---|
| 106 | // function getFilesRecursive($dir, $recurs_lev=0, $return=true) |
---|
| 107 | // { |
---|
| 108 | // static $output; |
---|
| 109 | // |
---|
| 110 | // $dir_handle = opendir($dir); |
---|
| 111 | // while ($dir_handle && ($file = readdir($dir_handle)) !== false) { |
---|
| 112 | // if (!preg_match('/^\./', $file)) { |
---|
| 113 | // if (is_dir($dir . '/' . $file) && $recurs_lev > 0) { |
---|
| 114 | // getFilesRecursive($dir . '/' . $file, $valid_extensions, $recurs_lev - 1); |
---|
| 115 | // } else if (!is_dir($dir . '/' . $file)) { |
---|
| 116 | // $output[] = $dir . '/' . $file; |
---|
| 117 | // } |
---|
| 118 | // } |
---|
| 119 | // } |
---|
| 120 | // if ($return) { |
---|
| 121 | // return $output; |
---|
| 122 | // } |
---|
| 123 | // } |
---|
| 124 | // |
---|
| 125 | // ?> |
---|