Progress
extends AbstractBaseApi
in package
Progress Class
Represents an asynchronous operation progress tracker in Canvas LMS. This class provides methods to track the status of long-running operations like content migrations, bulk updates, and file uploads.
Usage:
// Finding a progress by ID
$progress = Progress::find(123);
// Checking progress status
if ($progress->isCompleted()) {
$results = $progress->results;
echo "Operation completed successfully";
} elseif ($progress->isFailed()) {
echo "Operation failed: " . $progress->message;
} else {
echo "Progress: " . $progress->completion . "%";
}
// Polling until completion
$progress = Progress::find(123);
$completedProgress = $progress->waitForCompletion(300, 2); // 5 minutes max, 2 second intervals
// Cancelling an operation
$progress->cancel("User requested cancellation");
// LTI context progress
$progress = Progress::findInLtiContext(456, 123); // course_id, progress_id
// Static polling utility
$progress = Progress::pollUntilComplete(123, 300, 2);
Tags
Table of Contents
Constants
- STATE_COMPLETED : mixed = 'completed'
- STATE_FAILED : mixed = 'failed'
- STATE_QUEUED : mixed = 'queued'
- Workflow state constants
- STATE_RUNNING : mixed = 'running'
Properties
- $completion : int|null
- Percentage completed (0-100)
- $contextId : int|null
- The ID of the object the job is associated with
- $contextType : string|null
- The type of object (e.g., "Account", "Course", "User")
- $createdAt : DateTime|null
- When the job was created
- $id : int|null
- The unique identifier for the progress object
- $message : string|null
- Optional descriptive message about current status
- $results : mixed
- Optional results data when job completes
- $tag : string|null
- Identifies the type of operation being performed
- $updatedAt : DateTime|null
- When the progress was last updated
- $url : string|null
- Endpoint URL for retrieving progress updates
- $userId : int|null
- The ID of the user who initiated the job
- $workflowState : string|null
- Current status of the job (queued, running, completed, failed)
- $methodAliases : array<string, array<string|int, string>>
- Define method aliases
Methods
- __callStatic() : mixed
- Magic method to handle function aliases
- __construct() : mixed
- Progress constructor.
- all() : array<string|int, static>
- Get all pages of results
- cancel() : Progress
- Cancel a running operation
- find() : static
- Find a progress object by ID
- findInLtiContext() : Progress
- Find a progress object in LTI context
- get() : array<string|int, Progress>
- Required by ApiInterface - fetch all progress objects (not typically used)
- getCompletion() : int|null
- Get the completion percentage
- getCompletionPercentage() : float
- Get the completion percentage as a float (0.0 to 100.0)
- getContextId() : int|null
- Get the context ID
- getContextType() : string|null
- Get the context type
- getCreatedAt() : DateTime|null
- Get the creation date
- getId() : int|null
- Get the unique identifier
- getMessage() : string|null
- Get the status message
- getResults() : mixed
- Get the operation results
- getStatusDescription() : string
- Get a human-readable status description
- getTag() : string|null
- Get the operation tag
- getUpdatedAt() : DateTime|null
- Get the last update date
- getUrl() : string|null
- Get the progress URL
- getUserId() : int|null
- Get the user ID
- getWorkflowState() : string|null
- Get the workflow state
- isCompleted() : bool
- Check if the progress is completed
- isFailed() : bool
- Check if the progress has failed
- isFinished() : bool
- Check if the operation is finished (completed or failed)
- isInProgress() : bool
- Check if the operation is currently in progress (queued or running)
- isQueued() : bool
- Check if the progress is in queued state
- isRunning() : bool
- Check if the progress is in running state
- isSuccessful() : bool
- Check if the operation completed successfully
- overrideApiClient() : void
- Set an API client for this class only, leaving other resources on the shared default.
- paginate() : PaginationResult
- Get paginated results with metadata
- pollUntilComplete() : Progress
- Static utility to poll a progress until completion
- refresh() : Progress
- Refresh the progress object with latest data from API
- resetApiClients() : void
- Clear the shared default client and all per-class overrides.
- setApiClient() : void
- Set the shared default API client used by ALL resource classes.
- setCompletion() : void
- Set the completion percentage
- setContextId() : void
- Set the context ID
- setContextType() : void
- Set the context type
- setCreatedAt() : void
- Set the creation date
- setId() : void
- Set the unique identifier
- setMessage() : void
- Set the status message
- setResults() : void
- Set the operation results
- setTag() : void
- Set the operation tag
- setUpdatedAt() : void
- Set the last update date
- setUrl() : void
- Set the progress URL
- setUserId() : void
- Set the user ID
- setWorkflowState() : void
- Set the workflow state
- stream() : Generator<int, static>
- Stream all items across all pages one at a time.
- waitForCompletion() : Progress
- Wait for operation to complete with configurable polling
- castValue() : DateTime|mixed
- Cast a value to the correct type
- checkApiClient() : void
- Check if the API client is set, if not, instantiate a new one
- convertPaginatedResponseToModels() : array<string|int, static>
- Helper method to convert paginated response data to model instances
- createConfiguredHttpClient() : HttpClient
- Create an HttpClient with configured middleware
- createPaginationResult() : PaginationResult
- Helper method to create PaginationResult from paginated response
- getAliasMap() : array<string, string>
- Build a flat alias-to-method lookup from $methodAliases.
- getApiClient() : HttpClientInterface
- Get the API client, initializing if necessary
- getEndpoint() : string
- Get the API endpoint for this resource
- getPaginatedResponse() : PaginatedResponse
- Helper method to get paginated response from API endpoint
- hydrate() : void
- Assign API response data to properties with type coercion.
- parseJsonResponse() : array<string|int, mixed>
- Parse JSON response from API safely handling StreamInterface
- populate() : void
- Populate the object with new data
- toDtoArray() : array<string|int, mixed>
- Convert the object to an array
- validateContext() : void
- Validate a context type path segment against an allowlist.
Constants
STATE_COMPLETED
public
mixed
STATE_COMPLETED
= 'completed'
STATE_FAILED
public
mixed
STATE_FAILED
= 'failed'
STATE_QUEUED
Workflow state constants
public
mixed
STATE_QUEUED
= 'queued'
STATE_RUNNING
public
mixed
STATE_RUNNING
= 'running'
Properties
$completion
Percentage completed (0-100)
public
int|null
$completion
= null
$contextId
The ID of the object the job is associated with
public
int|null
$contextId
= null
$contextType
The type of object (e.g., "Account", "Course", "User")
public
string|null
$contextType
= null
$createdAt
When the job was created
public
DateTime|null
$createdAt
= null
$id
The unique identifier for the progress object
public
int|null
$id
= null
$message
Optional descriptive message about current status
public
string|null
$message
= null
$results
Optional results data when job completes
public
mixed
$results
= null
$tag
Identifies the type of operation being performed
public
string|null
$tag
= null
$updatedAt
When the progress was last updated
public
DateTime|null
$updatedAt
= null
$url
Endpoint URL for retrieving progress updates
public
string|null
$url
= null
$userId
The ID of the user who initiated the job
public
int|null
$userId
= null
$workflowState
Current status of the job (queued, running, completed, failed)
public
string|null
$workflowState
= null
$methodAliases
Define method aliases
protected
static array<string, array<string|int, string>>
$methodAliases
= ['get' => ['fetch', 'list'], 'all' => ['fetchAllPages', 'getAll', 'fetchAll'], 'paginate' => ['getPaginated', 'withPagination'], 'find' => ['one', 'getOne']]
Methods
__callStatic()
Magic method to handle function aliases
public
static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
- $name : string
- $arguments : array<string|int, mixed>
Tags
__construct()
Progress constructor.
public
__construct([array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string|int, mixed> = []
all()
Get all pages of results
public
static all([array<string, mixed> $params = [] ]) : array<string|int, static>
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Return values
array<string|int, static>cancel()
Cancel a running operation
public
cancel([string|null $message = null ]) : Progress
Parameters
- $message : string|null = null
-
Optional message to distinguish the cancellation reason
Tags
Return values
Progress —Updated progress object
find()
Find a progress object by ID
public
static find(int $id[, array<string|int, mixed> $params = [] ]) : static
Parameters
- $id : int
-
Progress ID
- $params : array<string|int, mixed> = []
-
Optional query parameters
Tags
Return values
staticfindInLtiContext()
Find a progress object in LTI context
public
static findInLtiContext(int $courseId, int $id) : Progress
Parameters
- $courseId : int
-
Course ID for LTI context
- $id : int
-
Progress ID
Tags
Return values
Progressget()
Required by ApiInterface - fetch all progress objects (not typically used)
public
static get([array<string|int, mixed> $params = [] ]) : array<string|int, Progress>
Parameters
- $params : array<string|int, mixed> = []
Tags
Return values
array<string|int, Progress>getCompletion()
Get the completion percentage
public
getCompletion() : int|null
Return values
int|nullgetCompletionPercentage()
Get the completion percentage as a float (0.0 to 100.0)
public
getCompletionPercentage() : float
Return values
floatgetContextId()
Get the context ID
public
getContextId() : int|null
Return values
int|nullgetContextType()
Get the context type
public
getContextType() : string|null
Return values
string|nullgetCreatedAt()
Get the creation date
public
getCreatedAt() : DateTime|null
Return values
DateTime|nullgetId()
Get the unique identifier
public
getId() : int|null
Return values
int|nullgetMessage()
Get the status message
public
getMessage() : string|null
Return values
string|nullgetResults()
Get the operation results
public
getResults() : mixed
getStatusDescription()
Get a human-readable status description
public
getStatusDescription() : string
Return values
stringgetTag()
Get the operation tag
public
getTag() : string|null
Return values
string|nullgetUpdatedAt()
Get the last update date
public
getUpdatedAt() : DateTime|null
Return values
DateTime|nullgetUrl()
Get the progress URL
public
getUrl() : string|null
Return values
string|nullgetUserId()
Get the user ID
public
getUserId() : int|null
Return values
int|nullgetWorkflowState()
Get the workflow state
public
getWorkflowState() : string|null
Return values
string|nullisCompleted()
Check if the progress is completed
public
isCompleted() : bool
Return values
boolisFailed()
Check if the progress has failed
public
isFailed() : bool
Return values
boolisFinished()
Check if the operation is finished (completed or failed)
public
isFinished() : bool
Return values
boolisInProgress()
Check if the operation is currently in progress (queued or running)
public
isInProgress() : bool
Return values
boolisQueued()
Check if the progress is in queued state
public
isQueued() : bool
Return values
boolisRunning()
Check if the progress is in running state
public
isRunning() : bool
Return values
boolisSuccessful()
Check if the operation completed successfully
public
isSuccessful() : bool
Return values
booloverrideApiClient()
Set an API client for this class only, leaving other resources on the shared default.
public
static overrideApiClient(HttpClientInterface $apiClient) : void
Parameters
- $apiClient : HttpClientInterface
paginate()
Get paginated results with metadata
public
static paginate([array<string, mixed> $params = [] ]) : PaginationResult
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Return values
PaginationResultpollUntilComplete()
Static utility to poll a progress until completion
public
static pollUntilComplete(int $id[, int $maxWaitSeconds = 300 ][, int $intervalSeconds = 2 ]) : Progress
Parameters
- $id : int
-
Progress ID to poll
- $maxWaitSeconds : int = 300
-
Maximum time to wait in seconds (default: 300)
- $intervalSeconds : int = 2
-
Initial polling interval in seconds (default: 2)
Tags
Return values
Progress —The completed progress object
refresh()
Refresh the progress object with latest data from API
public
refresh() : Progress
Tags
Return values
ProgressresetApiClients()
Clear the shared default client and all per-class overrides.
public
static resetApiClients() : void
setApiClient()
Set the shared default API client used by ALL resource classes.
public
static setApiClient(HttpClientInterface $apiClient) : void
Calling this on any resource (e.g. Course::setApiClient()) replaces the client for every resource, because relationship methods cross class boundaries ($course->enrollments() calls Enrollment internally). Use overrideApiClient() to scope a client to a single class, and resetApiClients() in test teardown to avoid state leaking.
Parameters
- $apiClient : HttpClientInterface
setCompletion()
Set the completion percentage
public
setCompletion(int|null $completion) : void
Parameters
- $completion : int|null
setContextId()
Set the context ID
public
setContextId(int|null $contextId) : void
Parameters
- $contextId : int|null
setContextType()
Set the context type
public
setContextType(string|null $contextType) : void
Parameters
- $contextType : string|null
setCreatedAt()
Set the creation date
public
setCreatedAt(DateTime|null $createdAt) : void
Parameters
- $createdAt : DateTime|null
setId()
Set the unique identifier
public
setId(int|null $id) : void
Parameters
- $id : int|null
setMessage()
Set the status message
public
setMessage(string|null $message) : void
Parameters
- $message : string|null
setResults()
Set the operation results
public
setResults(mixed $results) : void
Parameters
- $results : mixed
setTag()
Set the operation tag
public
setTag(string|null $tag) : void
Parameters
- $tag : string|null
setUpdatedAt()
Set the last update date
public
setUpdatedAt(DateTime|null $updatedAt) : void
Parameters
- $updatedAt : DateTime|null
setUrl()
Set the progress URL
public
setUrl(string|null $url) : void
Parameters
- $url : string|null
setUserId()
Set the user ID
public
setUserId(int|null $userId) : void
Parameters
- $userId : int|null
setWorkflowState()
Set the workflow state
public
setWorkflowState(string|null $workflowState) : void
Parameters
- $workflowState : string|null
stream()
Stream all items across all pages one at a time.
public
static stream([array<string|int, mixed> $params = [] ]) : Generator<int, static>
Unlike all(), only one page of raw data is held in memory at a time, making this safe for very large datasets (e.g. tens of thousands of enrollments):
foreach (User::stream(['per_page' => 100]) as $user) {
processUser($user);
}
Parameters
- $params : array<string|int, mixed> = []
-
Query parameters for the request
Tags
Return values
Generator<int, static>waitForCompletion()
Wait for operation to complete with configurable polling
public
waitForCompletion([int $maxWaitSeconds = 300 ][, int $intervalSeconds = 2 ]) : Progress
Parameters
- $maxWaitSeconds : int = 300
-
Maximum time to wait in seconds (default: 300 = 5 minutes)
- $intervalSeconds : int = 2
-
Initial polling interval in seconds (default: 2)
Tags
Return values
Progress —The completed progress object
castValue()
Cast a value to the correct type
protected
castValue(string $key, mixed $value) : DateTime|mixed
Parameters
- $key : string
- $value : mixed
Tags
Return values
DateTime|mixedcheckApiClient()
Check if the API client is set, if not, instantiate a new one
protected
static checkApiClient() : void
convertPaginatedResponseToModels()
Helper method to convert paginated response data to model instances
protected
static convertPaginatedResponseToModels(PaginatedResponse $paginatedResponse) : array<string|int, static>
Parameters
- $paginatedResponse : PaginatedResponse
Return values
array<string|int, static>createConfiguredHttpClient()
Create an HttpClient with configured middleware
protected
static createConfiguredHttpClient() : HttpClient
Return values
HttpClientcreatePaginationResult()
Helper method to create PaginationResult from paginated response
protected
static createPaginationResult(PaginatedResponse $paginatedResponse) : PaginationResult
Parameters
- $paginatedResponse : PaginatedResponse
Return values
PaginationResultgetAliasMap()
Build a flat alias-to-method lookup from $methodAliases.
protected
static getAliasMap() : array<string, string>
Return values
array<string, string>getApiClient()
Get the API client, initializing if necessary
protected
static getApiClient() : HttpClientInterface
Return values
HttpClientInterfacegetEndpoint()
Get the API endpoint for this resource
protected
static getEndpoint() : string
Return values
stringgetPaginatedResponse()
Helper method to get paginated response from API endpoint
protected
static getPaginatedResponse(string $endpoint[, array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
- $endpoint : string
-
The API endpoint path
- $params : array<string|int, mixed> = []
-
Query parameters for the request
Return values
PaginatedResponsehydrate()
Assign API response data to properties with type coercion.
protected
hydrate(array<string|int, mixed> $data) : void
Shared by the constructor and populate() so objects keep the same type guarantees after save()/update() round-trips as on creation.
Parameters
- $data : array<string|int, mixed>
parseJsonResponse()
Parse JSON response from API safely handling StreamInterface
protected
static parseJsonResponse(ResponseInterface $response) : array<string|int, mixed>
Parameters
- $response : ResponseInterface
Return values
array<string|int, mixed>populate()
Populate the object with new data
protected
populate(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Tags
toDtoArray()
Convert the object to an array
protected
toDtoArray() : array<string|int, mixed>
Return values
array<string|int, mixed>validateContext()
Validate a context type path segment against an allowlist.
protected
static validateContext(string|null $contextType, array<int, string> $allowed) : void
Context types are interpolated into URL paths; validating against the contexts Canvas actually supports prevents crafted values from injecting extra path segments or query parameters.
Parameters
- $contextType : string|null
-
The context type (plural, e.g. 'courses'); null is ignored
- $allowed : array<int, string>
-
Allowed context types