Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add restoreUsers to Client.php #122

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

mauicode26
Copy link
Contributor

@mauicode26 mauicode26 commented Aug 11, 2024

Updates:

  • Add restoreUsers method to Client.php

The restoreUsers functionality can be tested with the following code after the commits are implemented:

<?php

use GetStream\StreamChat\Client;

require_once "./vendor/autoload.php";

$client = new Client($_ENV['STREAM_KEY'], $_ENV['STREAM_SECRET']);

# Create users
$user_1 = [
    'id' => 'u-70', # Have to keep updating this between testing this out-- you cannot upsert a previously deleted user ID
    'role' => 'admin',
    'name' => 'Bob',
];

# Add users to Stream
$client->upsertUsers([$user_1]);

# Users Query Object
$queryUsersInput = [
    'id' => ['$in' => [$user_1['id']] ],
];

# SOFT-delete user
$delete_users_response = $client->deleteUsers([$user_1['id']], [
    'user' => 'soft',
    'messages' => 'soft'
]);

sleep(3); # Let the delete task complete before fetching it
$task = $client->getTask($delete_users_response['task_id']);

# Restore user once deleteTask is complete
if($task["status"] == "completed") {
    echo 'Now will try to restore a soft-deleted user...';

    $client->restoreUsers([$user_1['id']]);
    $users = $client->queryUsers($queryUsersInput)['users'];

    echo 'Queried Users: ' . PHP_EOL;
    var_dump($users);
}

# HARD-delete user
$delete_users_response = $client->deleteUsers([$user_1['id']], [
    'user' => 'hard',
    'messages' => 'hard'
]);

sleep(3); # Let the delete task complete before fetching it
$task = $client->getTask($delete_users_response['task_id']);

# Try to restore user once deleteTask is complete
if($task["status"] == "completed") {
    echo 'Now will try to restore a hard-deleted user...';
    $client->restoreUsers([$user_1['id']]);
    # 404 Errors out
}

@totalimmersion totalimmersion enabled auto-merge (squash) September 4, 2024 13:06
@totalimmersion totalimmersion merged commit bbab28b into GetStream:main Sep 4, 2024
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants