Jump to content

Issue with Source/ActiveRecord


TheOnlyDroid

Recommended Posts

For some reason, while running a task its unable to find the class '\IPS\avovix\Request' when running a foreach loop with an ActiveRecordIterator

namespace IPS\avovix;


/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

class _Request extends \IPS\Patterns\ActiveRecord
{
	const STATUS_PENDING	= 'pend';
	const STATUS_COMPLETED	= 'comp';
	const STATUS_FAILED	= 'fail';

	/**
	 * @brief	Multiton Store
	 */
	protected static $multitons;

	/**
	 * @brief	Database Table
	 */
	public static $databaseTable = 'avovix_datarequests';
	
	/**
	 * @brief	Database Prefix
	 */
	public static $databasePrefix = 'r_';


	public static function loadAndCheckPerms( $id )
	{
		$obj = static::load( $id );
		
		if ( !$obj->canView() )
		{
			throw new \OutOfRangeException;
		}

		return $obj;
	}

	public function setDefaultValues()
	{
		$this->status = static::STATUS_PENDING;
		$this->date = new \IPS\DateTime;
		$this->_data['member'] = 0;
	}

	/**
	 * @brief	Member
	 */
	protected $_member;

	public function get_member()
	{
		if ( $this->_member === NULL )
		{
			try
			{
				$this->_member = \IPS\Member::load($this->_data['member']);
				
				if ( !$this->_member->member_id )
				{
					throw new \OutOfRangeException;
				}
			}
			catch ( \OutOfRangeException $e )
			{
			}
		}
		
		return $this->_member;
	}
	
	/**
	 * Set member
	 *
	 * @param	\IPS\Member
	 * @return	void
	 */
	public function set_member( \IPS\Member $member )
	{
		$this->_data['member'] = (int) $member->member_id;
		$this->_member = NULL;
	}

	/**
	 * Get date
	 *
	 * @return	\IPS\DateTime
	 */
	public function get_date()
	{
		return \IPS\DateTime::ts( $this->_data['date'] );
	}
	
	/**
	 * Set date
	 *
	 * @param	\IPS\DateTime	$date	The invoice date
	 * @return	void
	 */
	public function set_date( \IPS\DateTime $date )
	{
		$this->_data['date'] = $date->getTimestamp();
	}
}
class _DataPackages extends \IPS\Task
{
	/**
	 * Execute
	 *
	 * If ran successfully, should return anything worth logging. Only log something
	 * worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
	 * If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
	 * Tasks should execute within the time of a normal HTTP request.
	 *
	 * @return	mixed	Message to log or NULL
	 * @throws	\IPS\Task\Exception
	 */
	public function execute()
	{
		$processedDate = \IPS\DateTime::create();

		/*
		foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'avovix_datarequests', array( 'r_status=?', 'pend', 'r_date ASC', 100 )), 'IPS\avovix\Request' ) as $request )
		{
			\IPS\Session::i()->log( 'avovix_test_log' );
		}*/

		foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'avovix_datarequests', array( 'r_status=?', \IPS\avovix\Request::STATUS_PENDING ), 'r_date ASC', 100), '\IPS\avovix\Request' ) as $request )
		{

		}
	}
	
	/**
	 * Cleanup
	 *
	 * If your task takes longer than 15 minutes to run, this method
	 * will be called before execute(). Use it to clean up anything which
	 * may not have been done
	 *
	 * @return	void
	 */
	public function cleanup()
	{
		
	}
}

 

Link to comment
Share on other sites

1 hour ago, teraßyte said:

At a first quick look the code seems okay. Can you paste here the exact error you're getting? The backtrace might help  understand the problem.

 

Error thrown with message "Class 'IPS\avovix\Request' not found"

Stacktrace:
#6 Error in C:\xampp\htdocs\ipboardx\applications\avovix\tasks\DataPackages.php:47
#5 IPS\avovix\tasks\_DataPackages:execute in C:\xampp\htdocs\ipboardx\system\Task\Task.php:248
#4 IPS\_Task:run in C:\xampp\htdocs\ipboardx\applications\core\modules\admin\settings\advanced.php:630
#3 IPS\core\modules\admin\settings\_advanced:runTask in C:\xampp\htdocs\ipboardx\system\Dispatcher\Controller.php:85
#2 IPS\Dispatcher\_Controller:execute in C:\xampp\htdocs\ipboardx\applications\core\modules\admin\settings\advanced.php:34
#1 IPS\core\modules\admin\settings\_advanced:execute in C:\xampp\htdocs\ipboardx\system\Dispatcher\Dispatcher.php:146
#0 IPS\_Dispatcher:run in C:\xampp\htdocs\ipboardx\admin\index.php:14

Folder Structure

 

Link to comment
Share on other sites

15 minutes ago, TheOnlyDroid said:

 


Error thrown with message "Class 'IPS\avovix\Request' not found"

Stacktrace:
#6 Error in C:\xampp\htdocs\ipboardx\applications\avovix\tasks\DataPackages.php:47
#5 IPS\avovix\tasks\_DataPackages:execute in C:\xampp\htdocs\ipboardx\system\Task\Task.php:248
#4 IPS\_Task:run in C:\xampp\htdocs\ipboardx\applications\core\modules\admin\settings\advanced.php:630
#3 IPS\core\modules\admin\settings\_advanced:runTask in C:\xampp\htdocs\ipboardx\system\Dispatcher\Controller.php:85
#2 IPS\Dispatcher\_Controller:execute in C:\xampp\htdocs\ipboardx\applications\core\modules\admin\settings\advanced.php:34
#1 IPS\core\modules\admin\settings\_advanced:execute in C:\xampp\htdocs\ipboardx\system\Dispatcher\Dispatcher.php:146
#0 IPS\_Dispatcher:run in C:\xampp\htdocs\ipboardx\admin\index.php:14

Folder Structure

 

In this instance, the file is in /sources/personal/Request.php - as such, the autoloader expects the namespace to be IPS\avovix\personal. So you need to either:

  • Add personal to your declared namespace, and then call the class as such (\IPS\avovix\personal\Request.php).
  • Move the Request.php file to the root of the sources folder, or in a folder with the same name (ex: /sources/Request/Request.php).
Link to comment
Share on other sites

 

12 minutes ago, Ryan Ashbrook said:

In this instance, the file is in /sources/personal/Request.php - as such, the autoloader expects the namespace to be IPS\avovix\personal. So you need to either:

  • Add personal to your declared namespace, and then call the class as such (\IPS\avovix\personal\Request.php).
  • Move the Request.php file to the root of the sources folder, or in a folder with the same name (ex: /sources/Request/Request.php).

Well that's the issue, regardless of where, what or how the file is written, read; The issue remains the same; It still has no idea where it/what it is.

Link to comment
Share on other sites

1 minute ago, newbie LAC said:

What did you change?

Show changed code and folder structure

The namespace was changed, as suggested.

<?php
namespace IPS\avovix\personal;


/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

class _Request extends \IPS\Patterns\ActiveRecord
{
	
Class 'IPS\avovix\personal\Request' not found

Error thrown with message "Class 'IPS\avovix\personal\Request' not found"

Stacktrace:
#6 Error in C:\xampp\htdocs\ipboardx\applications\avovix\tasks\DataPackages.php:39
#5 IPS\avovix\tasks\_DataPackages:execute in C:\xampp\htdocs\ipboardx\system\Task\Task.php:248
#4 IPS\_Task:run in C:\xampp\htdocs\ipboardx\applications\core\modules\admin\settings\advanced.php:630
#3 IPS\core\modules\admin\settings\_advanced:runTask in C:\xampp\htdocs\ipboardx\system\Dispatcher\Controller.php:85
#2 IPS\Dispatcher\_Controller:execute in C:\xampp\htdocs\ipboardx\applications\core\modules\admin\settings\advanced.php:34
#1 IPS\core\modules\admin\settings\_advanced:execute in C:\xampp\htdocs\ipboardx\system\Dispatcher\Dispatcher.php:146
#0 IPS\_Dispatcher:run in C:\xampp\htdocs\ipboardx\admin\index.php:14
<?php
/**
 * @brief		DataPackages Task
 * @author		<a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
 * @copyright	(c) Invision Power Services, Inc.
 * @license		https://www.invisioncommunity.com/legal/standards/
 * @package		Invision Community
 * @subpackage	avovix
 * @since		30 Sep 2018
 */

namespace IPS\avovix\tasks;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * DataPackages Task
 */
class _DataPackages extends \IPS\Task
{
	/**
	 * Execute
	 *
	 * If ran successfully, should return anything worth logging. Only log something
	 * worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
	 * If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
	 * Tasks should execute within the time of a normal HTTP request.
	 *
	 * @return	mixed	Message to log or NULL
	 * @throws	\IPS\Task\Exception
	 */
	public function execute()
	{
		foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'avovix_datarequests', array('r_status=?', \IPS\avovix\personal\Request::STATUS_PENDING )), 'IPS\avovix\personal\Request' ) as $request)
		{

		}
	}
	
	/**
	 * Cleanup
	 *
	 * If your task takes longer than 15 minutes to run, this method
	 * will be called before execute(). Use it to clean up anything which
	 * may not have been done
	 *
	 * @return	void
	 */
	public function cleanup()
	{
		
	}
}

 

Link to comment
Share on other sites

4 minutes ago, TheOnlyDroid said:

The namespace was changed, as suggested.

Again

Quote

Application classes
Classname structure: \IPS\app\Namespace\Class (note that the application key is lowercase, but the parts after are PascalCase)
Location on disk: applications/app/sources/Namespace/Class.php

In your case Personal not personal

namespace IPS\avovix\Personal;

+ rename the folder from personal to Personal

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...