78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Hourly script to export open projects from Zoho Projects
|
|
*
|
|
* Usage: php scripts/export_projects.php [--include-tasks] [--format=json|csv]
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
// Autoloader
|
|
spl_autoload_register(function ($class) {
|
|
$prefix = 'App\\';
|
|
$baseDir = __DIR__ . '/../src/';
|
|
|
|
$len = strlen($prefix);
|
|
if (strncmp($prefix, $class, $len) !== 0) {
|
|
return;
|
|
}
|
|
|
|
$relativeClass = substr($class, $len);
|
|
$file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';
|
|
|
|
if (file_exists($file)) {
|
|
require $file;
|
|
}
|
|
});
|
|
|
|
use App\Core\ZohoClient;
|
|
use App\Services\ProjectsService;
|
|
use App\Export\ExportManager;
|
|
use App\Utils\Logger;
|
|
|
|
// Load configuration
|
|
$config = require __DIR__ . '/../config/config.php';
|
|
|
|
// Initialize logger
|
|
$logger = new Logger($config['log_file'], $config['log_level']);
|
|
|
|
try {
|
|
$logger->info('Starting Zoho Projects export');
|
|
|
|
// Parse command line options
|
|
$options = getopt('', ['include-tasks', 'format:']);
|
|
$includeTasks = isset($options['include-tasks']);
|
|
$format = $options['format'] ?? $config['export']['format'];
|
|
|
|
// Initialize Zoho client
|
|
$client = new ZohoClient($config);
|
|
|
|
// Initialize Projects service
|
|
$projectsService = new ProjectsService($client, $config);
|
|
|
|
// Fetch open projects
|
|
$logger->info('Fetching open projects', ['include_tasks' => $includeTasks]);
|
|
$projects = $projectsService->getOpenProjects($includeTasks);
|
|
|
|
$logger->info('Fetched projects', ['count' => count($projects)]);
|
|
|
|
// Export data
|
|
$exportManager = new ExportManager($config['export']['output_dir'], $format);
|
|
$filepath = $exportManager->export($projects, 'open_projects');
|
|
|
|
$logger->info('Export completed', ['filepath' => $filepath]);
|
|
|
|
echo "Export completed successfully!\n";
|
|
echo "Records exported: " . count($projects) . "\n";
|
|
echo "Output file: {$filepath}\n";
|
|
|
|
} catch (\Exception $e) {
|
|
$logger->error('Export failed', [
|
|
'error' => $e->getMessage(),
|
|
'trace' => $e->getTraceAsString(),
|
|
]);
|
|
|
|
echo "Error: " . $e->getMessage() . "\n";
|
|
exit(1);
|
|
}
|