Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,16 +12,26 @@
|
||||
namespace IPS\core\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\core\Rss\Import;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Task;
|
||||
use IPS\Task\Exception;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* rssimport Task
|
||||
*/
|
||||
class _rssimport extends \IPS\Task
|
||||
class rssimport extends Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
@@ -32,27 +42,27 @@ class _rssimport extends \IPS\Task
|
||||
* Tasks should execute within the time of a normal HTTP request.
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : mixed
|
||||
{
|
||||
$timeCheck = new \IPS\DateTime;
|
||||
$timeCheck->sub( new \DateInterval( 'PT10M' ) );
|
||||
$timeCheck = new DateTime;
|
||||
$timeCheck->sub( new DateInterval( 'PT10M' ) );
|
||||
|
||||
$this->runUntilTimeout(function() use ( $timeCheck ) {
|
||||
try
|
||||
{
|
||||
$feed = \IPS\core\Rss\Import::constructFromData( \IPS\Db::i()->select( '*', 'core_rss_import', array( 'rss_import_enabled=1 AND rss_import_last_import<?', $timeCheck->getTimestamp() ), 'rss_import_last_import ASC', 1 )->first() );
|
||||
$feed = Import::constructFromData( Db::i()->select( '*', 'core_rss_import', array( 'rss_import_enabled=1 AND rss_import_last_import<?', $timeCheck->getTimestamp() ), 'rss_import_last_import ASC', 1 )->first() );
|
||||
$feed->run();
|
||||
}
|
||||
/* There's nothing more left to process */
|
||||
catch ( \UnderflowException $e )
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
/* Check to see if there are any feeds.. If no feed, we can disable the task */
|
||||
if( !\IPS\Db::i()->select( 'count(rss_import_id)', 'core_rss_import', array( 'rss_import_enabled=1' ), NULL, 1 )->first() )
|
||||
if( !Db::i()->select( 'count(rss_import_id)', 'core_rss_import', array( 'rss_import_enabled=1' ), NULL, 1 )->first() )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'rssimport' ) );
|
||||
Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'rssimport' ) );
|
||||
}
|
||||
|
||||
/* No further processing needed */
|
||||
@@ -62,17 +72,19 @@ class _rssimport extends \IPS\Task
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
/* If there is an error, we need to log it but the error should not prevent other feeds from importing */
|
||||
if ( isset( $feed ) AND ( $feed instanceof \IPS\core\Rss\Import ) )
|
||||
if ( isset( $feed ) AND ( $feed instanceof Import ) )
|
||||
{
|
||||
$feed->last_import = time();
|
||||
$feed->save();
|
||||
}
|
||||
throw new \IPS\Task\Exception( $this, $e->getMessage() );
|
||||
throw new Exception( $this, $e->getMessage() );
|
||||
}
|
||||
|
||||
/* Run again to see if there's anything left */
|
||||
return TRUE;
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user