first commit
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Initial authentication script for Zoho OAuth2
|
||||
*
|
||||
* Step 1: Run this script to get the authorization URL
|
||||
* Step 2: Visit the URL and authorize the application
|
||||
* Step 3: Copy the authorization code from the redirect URL
|
||||
* Step 4: Run: php scripts/authenticate.php --code=YOUR_CODE
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
// Load configuration
|
||||
$config = require __DIR__ . '/../config/config.php';
|
||||
|
||||
// Parse command line options
|
||||
$options = getopt('', ['service:', 'code:', 'help']);
|
||||
|
||||
$service = $options['service'] ?? 'projects';
|
||||
$help = isset($options['help']);
|
||||
|
||||
if ($help) {
|
||||
echo "Zoho OAuth2 Authentication Script\n";
|
||||
echo "=================================\n\n";
|
||||
echo "Usage:\n";
|
||||
echo " 1. Generate authorization URL:\n";
|
||||
echo " php scripts/authenticate.php --service=projects\n\n";
|
||||
echo " 2. Visit the URL, authorize, and copy the code from redirect URL\n\n";
|
||||
echo " 3. Exchange code for tokens:\n";
|
||||
echo " php scripts/authenticate.php --service=projects --code=YOUR_CODE\n\n";
|
||||
echo "Options:\n";
|
||||
echo " --service Zoho service (projects, desk)\n";
|
||||
echo " --code Authorization code from OAuth flow\n";
|
||||
echo " --help Show this help message\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$client = new ZohoClient($config);
|
||||
|
||||
if (isset($options['code'])) {
|
||||
// Exchange authorization code for tokens
|
||||
$code = $options['code'];
|
||||
|
||||
echo "Exchanging authorization code for tokens...\n";
|
||||
|
||||
try {
|
||||
$client->exchangeCodeForTokens($code, $service);
|
||||
echo "Success! Tokens have been saved.\n";
|
||||
echo "You can now run the export script.\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
// Generate authorization URL
|
||||
try {
|
||||
$authUrl = $client->getAuthorizationUrl($service);
|
||||
echo "Authorization URL for Zoho {$service}:\n";
|
||||
echo "========================================\n";
|
||||
echo "{$authUrl}\n\n";
|
||||
echo "1. Visit this URL in your browser\n";
|
||||
echo "2. Authorize the application\n";
|
||||
echo "3. Copy the 'code' parameter from the redirect URL\n";
|
||||
echo "4. Run: php scripts/authenticate.php --service={$service} --code=YOUR_CODE\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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);
|
||||
}
|
||||
Reference in New Issue
Block a user