64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Pandy06269\iCalImporter;
|
||
|
|
||
|
use Pandy06269\iCalImporter\includes\Event;
|
||
|
use Pandy06269\iCalImporter\includes\FileReader;
|
||
|
use Pandy06269\iCalImporter\includes\ICSFileReader;
|
||
|
|
||
|
//define('DEBUG', true);
|
||
|
|
||
|
function autoload_include_file($class)
|
||
|
{
|
||
|
$class = substr($class, strlen('Pandy06269\\iCalImporter\\'));
|
||
|
|
||
|
$filePath = sprintf('%s/%s.php', __DIR__, str_replace('\\', DIRECTORY_SEPARATOR, $class));
|
||
|
require_once $filePath;
|
||
|
}
|
||
|
|
||
|
spl_autoload_register('\Pandy06269\iCalImporter\autoload_include_file');
|
||
|
|
||
|
if ($argc !== 3)
|
||
|
{
|
||
|
echo sprintf('Usage: %s <path to ical file> <path to Drupal config file>' . PHP_EOL, $argv[0]);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
try
|
||
|
{
|
||
|
$pathToICSFile = trim($argv[1]);
|
||
|
$pathToDrupalConfig = trim($argv[2]);
|
||
|
|
||
|
$icsReader = new ICSFileReader($pathToICSFile);
|
||
|
$drupalReader = new FileReader($pathToDrupalConfig);
|
||
|
|
||
|
echo sprintf('Reading iCal data from %s' . PHP_EOL, $icsReader->getPath());
|
||
|
echo sprintf('Using Drupal connection details from %s' . PHP_EOL, $drupalReader->getPath());
|
||
|
echo '---' . PHP_EOL;
|
||
|
|
||
|
$events = $icsReader->getEvents();
|
||
|
|
||
|
echo sprintf('%d event%s found' . PHP_EOL, count($events), count($events) == 1 ? '' : 's');
|
||
|
echo '---' . PHP_EOL;
|
||
|
|
||
|
/** @var Event $event */
|
||
|
$index = 0;
|
||
|
foreach ($events as $event)
|
||
|
{
|
||
|
echo sprintf('%d: %s | %s' . PHP_EOL, $index, $event->getUid(), $event->getStartDate()->format('H:i:s d/M/Y'));
|
||
|
echo $event->getTitle() . PHP_EOL;
|
||
|
|
||
|
if (strlen($event->getDescription()))
|
||
|
{
|
||
|
echo PHP_EOL . $event->getDescription() . PHP_EOL;
|
||
|
}
|
||
|
|
||
|
echo '---' . PHP_EOL;
|
||
|
$index++;
|
||
|
}
|
||
|
}
|
||
|
catch (\Exception $e)
|
||
|
{
|
||
|
echo sprintf('Caught exception: %s' . PHP_EOL, $e->getMessage());
|
||
|
echo $e->getTraceAsString();
|
||
|
}
|