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 initial push #4

Merged
merged 74 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
e578aa6
Initial Push
PineappleIOnic Jan 5, 2023
2d467d0
Initial Push 2
PineappleIOnic Jan 17, 2023
8f769c3
Implement Supabase and improve Firebase and Appwrite adapters
PineappleIOnic Jan 18, 2023
649bffa
Add NHost and Tests
PineappleIOnic Jan 19, 2023
0770288
Continue code cleanup
PineappleIOnic Jan 24, 2023
d57cd4f
Add Appwrite Source Adapter
PineappleIOnic Jan 25, 2023
cb533f5
Implement Database Support
PineappleIOnic Feb 13, 2023
20615de
Add Subcollection Support for Firebase
PineappleIOnic Feb 16, 2023
0f6e82b
Update Psalm
PineappleIOnic Feb 16, 2023
1c0792c
Update composer.json
PineappleIOnic Feb 16, 2023
4c9bddb
Add getCurrent resource and populate Progress class
PineappleIOnic Feb 16, 2023
d707dc2
Stop using 8.2 features
PineappleIOnic Feb 17, 2023
a33d9e1
Fix User.php
PineappleIOnic Feb 17, 2023
fb05b47
Improve Checks function, start work on rewriting tests
PineappleIOnic Feb 23, 2023
347151f
Capitalise and normalise transfer resource names
PineappleIOnic Feb 24, 2023
a811b1d
Continue work on newer permission checks
PineappleIOnic Feb 24, 2023
8180478
Continue Work on validation
PineappleIOnic Feb 24, 2023
84b543d
Implement new report based check system
PineappleIOnic Feb 24, 2023
6260c98
Rollback Update
PineappleIOnic Feb 24, 2023
fae74e2
Use correct status codes
PineappleIOnic Feb 24, 2023
3949a5b
Various Fixes and Other things found while implementing API
PineappleIOnic Mar 22, 2023
3173861
First iteration
PineappleIOnic Mar 27, 2023
c042ac6
Improve algorithm for converting Indexes from Jake's feedback
PineappleIOnic Mar 27, 2023
ab75702
Finish Implementing Indexes for both NHost and Supabase
PineappleIOnic Mar 27, 2023
3138d03
Merge pull request #2 from utopia-php/feat-implement-indexes
PineappleIOnic Mar 27, 2023
568ba73
Finish Implementing Document support in both Nhost and Supabase
PineappleIOnic Mar 29, 2023
c17bb83
Implement Full Appwrite support
PineappleIOnic Apr 3, 2023
d32b002
Move playground out of tmp
PineappleIOnic Apr 3, 2023
020599b
Add and run formatter
PineappleIOnic Apr 3, 2023
579e024
Fix Playground Imports
PineappleIOnic Apr 3, 2023
e8d601a
Implement File Transfers for Appwrite
PineappleIOnic Apr 17, 2023
2318e6d
Begin implementing Relationships
PineappleIOnic Apr 17, 2023
fb2ad63
Merge branch 'feat-implement-files' into feat-initial-push
PineappleIOnic Apr 17, 2023
2373dc3
Delete .vscode directory
PineappleIOnic Apr 26, 2023
1745d1e
Continue Refactor work
PineappleIOnic Apr 26, 2023
9dcbdea
Update Target.php
PineappleIOnic Apr 26, 2023
bc47b31
Rework Appwrite File Transfer Client
PineappleIOnic Apr 26, 2023
04e2e08
Continue Refactor
PineappleIOnic May 10, 2023
417018c
Start implementing tests and change check with report
PineappleIOnic May 11, 2023
b8d27a2
Update progress tracking system
PineappleIOnic May 12, 2023
32a602b
Update Transfer.php
PineappleIOnic May 12, 2023
f56c320
Update Firebase.php
PineappleIOnic May 12, 2023
a8f4c12
Update Transfer.php
PineappleIOnic May 12, 2023
fec1470
Update Transfer.php
PineappleIOnic May 12, 2023
f1d41d3
add storage to firebase and change database system
PineappleIOnic May 17, 2023
ee8dd20
Run phpcbf and fix the linter issues
PineappleIOnic May 17, 2023
2b76b31
Merge File and FileData and remove psalm for pint
PineappleIOnic Jun 5, 2023
84c0be8
Rename ResourceCache to just Cache
PineappleIOnic Jun 5, 2023
8ee17a1
Continue work on PR updates
PineappleIOnic Jun 5, 2023
e45e1ae
Fix Visibility
PineappleIOnic Jun 5, 2023
53ee401
Update NHost.php
PineappleIOnic Jun 5, 2023
9f1c522
Continue Addressing PR issues
PineappleIOnic Jun 5, 2023
2e0cd4d
Continue work on tests
PineappleIOnic Jun 14, 2023
560bb93
Continue work on types
PineappleIOnic Jun 17, 2023
606e739
Merge branch 'feat-implement-tests' into feat-initial-push
PineappleIOnic Jun 17, 2023
6116d8d
Improve Null Username handling
PineappleIOnic Jun 17, 2023
c1861d2
Continue Work
PineappleIOnic Jun 19, 2023
75c4371
Update .env.example
PineappleIOnic Jun 21, 2023
e3af0cb
Update tests/e2e/adapters/MockSource.php
PineappleIOnic Jun 21, 2023
4aa03e9
Continue work on PR
PineappleIOnic Jun 21, 2023
b92c711
Update src/Transfer/Resources/Database/Attribute.php
PineappleIOnic Jun 21, 2023
209cb69
Update Attribute.php
PineappleIOnic Jun 21, 2023
af396c4
Merge branch 'feat-initial-push' of https://github.com/utopia-php/tra…
PineappleIOnic Jun 21, 2023
2119dfb
Continue work on attributes
PineappleIOnic Jun 21, 2023
28730fa
Update tests/Transfer/E2E/Sources/SourceCore.php
PineappleIOnic Jun 21, 2023
99ea59d
Update src/Transfer/Source.php
PineappleIOnic Jun 21, 2023
38d1235
Continue Work
PineappleIOnic Jun 21, 2023
16c6c50
Normalise const convention
PineappleIOnic Jun 21, 2023
15eea1c
Update hash vars
PineappleIOnic Jun 21, 2023
464ac5c
Fix more namessssss
PineappleIOnic Jun 21, 2023
9b73954
Fix Supabase
PineappleIOnic Jun 21, 2023
c1af62d
Update Supabase.php
PineappleIOnic Jun 21, 2023
9c8ccd8
Update Firebase.php
PineappleIOnic Jun 21, 2023
736a8f8
Fix Firebase
PineappleIOnic Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Initial Push 2
+ Completed first implementation of both Appwrite and Firebase adapters with the core Transfer class logic ready
  • Loading branch information
PineappleIOnic committed Jan 17, 2023
commit 2d467d07c8a05a150d929a458eed603a82c2af9d
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
APPWRITE_TEST_PROJECT=testProject
APPWRITE_TEST_ENDPONT=http:https://localhost/v1
APPWRITE_TEST_KEY=xxxxxxxxxxxxxxxxxx

FIREBASE_TEST_PROJECT=testProject
FIREBASE_TEST_ACCOUNT='{type: "service_account", ...}'
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Bradley Schofield
Copyright (c) 2022 Utopia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"php": ">=8.0",
"utopia-php/cli": "^0.14.0",
"google/apiclient": "^2.12.1",
"kreait/firebase-php": "^7.0",
"appwrite/appwrite": "^7.2"
},
"require-dev": {
Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
<directory>./tests/Transfer/Sources</directory>
<directory>./tests/Transfer/Destinations</directory>
<directory>./tests/Transfer/Transfers</directory>
</testsuite>
</testsuites>
</phpunit>
27 changes: 22 additions & 5 deletions src/Transfer/Destination.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ abstract class Destination
*/
protected $logs = [];

/**
* Resource Cache
*
* @var array $resourceCache
*/
protected $resourceCache = [];

/**
* Internal Adapter State
*
Expand Down Expand Up @@ -63,25 +70,35 @@ public function registerLogs(array &$logs): void {
}

/**
* Transfer Resources between adapters
* Register Resource Cache
*
* @param array &$cache
*/
public function registerResourceCache(array &$cache): void {
$this->resourceCache = &$cache;
}

/**
* Transfer Resources to Destination from Source callback
*
* @param array $resources
* @param callable $callback
*/
public function run(array $resources, callable $callback, Source $source): void {
foreach ($resources as $resource) {
if (!in_array($resource, $this->getSupportedResources())) {
$this->logs[Log::FATAL] = new Log("Cannot Transfer unsupported resource: '".$resource."'");
throw new \Exception("Cannot Transfer unsupported resource: '".$resource."'");
}

$source->run($resources, function (Log $currentLog, string $resource, array &$resourceCache) {
switch ($resource) {
$source->run($resources, function (Log $currentLog, string $resourceType, array $resource) use ($callback) {
switch ($resourceType) {
case Transfer::RESOURCE_USERS: {
$this->importUsers($resourceCache);
$resourceCache = [];
$this->importUsers($resource);
break;
}
}
$callback($currentLog, $resourceType, $resource);
});
}
}
Expand Down
61 changes: 39 additions & 22 deletions src/Transfer/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Appwrite\Client;
use Appwrite\Services\Users;
use Utopia\Transfer\Destination;
use Utopia\Transfer\Hash;
use Utopia\Transfer\Resources\Hash;
use Utopia\Transfer\Log;
use Utopia\Transfer\Resources\User;
use Utopia\Transfer\Transfer;
Expand Down Expand Up @@ -47,19 +47,31 @@ public function getSupportedResources(): array {

public function check(array $resources = []): bool
{
//TODO: Implement check() method.
$auth = new Users($this->client);

try {
$auth->list();
} catch (\Exception $e) {
$this->logs[Log::ERROR] = new Log($e->getMessage());
return false;
}

return true;
}

public function importPasswordUser(User $user): void
public function importPasswordUser(User $user): array|null
{
$authentication = new Users($this->client);
$auth = new Users($this->client);
$hash = $user->getPasswordHash();
$result = null;

if (empty($hash->getHash()) || empty($hash->getSalt())) {
throw new \Exception('User password hash is empty');
}

switch ($hash->getAlgorithm()) {
case Hash::SCRYPT_MODIFIED:
$result = $authentication->createScryptModifiedUser(
$result = $auth->createScryptModifiedUser(
$user->getId(),
$user->getEmail(),
$hash->getHash(),
Expand All @@ -70,39 +82,40 @@ public function importPasswordUser(User $user): void
);
break;
case Hash::BCRYPT:
$result = $authentication->createBcryptUser(
$result = $auth->createBcryptUser(
$user->getId(),
$user->getEmail(),
$hash->getHash(),
$user->getEmail()
);
break;
case Hash::ARGON2:
$result = $authentication->createArgon2User(
$result = $auth->createArgon2User(
$user->getId(),
$user->getEmail(),
$hash->getHash(),
$user->getEmail()
);
break;
case Hash::SHA:
$result = $authentication->createShaUser(
case Hash::SHA256:
$result = $auth->createShaUser(
$user->getId(),
$user->getEmail(),
$hash->getHash(),
'sha256',
$user->getEmail()
);
break;
case Hash::PHPASS:
$result = $authentication->createPHPassUser(
$result = $auth->createPHPassUser(
$user->getId(),
$user->getEmail(),
$hash->getHash(),
$user->getEmail()
);
break;
case Hash::SCRYPT:
$result = $authentication->createScryptUser(
$result = $auth->createScryptUser(
$user->getId(),
$user->getEmail(),
$hash->getHash(),
Expand All @@ -116,26 +129,30 @@ public function importPasswordUser(User $user): void
break;
}

if (!$result) {
throw new \Exception('Failed to import user: "'.$user->getId().'"');
}
return $result;
}

public function importUsers(array $users): void
{
$auth = new Users($this->client);

foreach ($users as $user) {
/** @var \Utopia\Transfer\Resources\User $user */
try {
switch ($user->getType()) {
case User::AUTH_EMAIL:
$this->importPasswordUser($user);
break;
default:
$this->logs[] = new Log(Log::WARNING, 'Not copying user: "'.$user->getId().'" due to it being an account type: "'.$user->getType().'".', \time(), $user);
//TODO: Implement other auth types, talk to Eldadfux about API's requried (Might have to resort to using Console SDK).
$createdUser = in_array(User::TYPE_EMAIL, $user->getTypes()) ? $this->importPasswordUser($user) : $auth->create($user->getId(), $user->getEmail(), $user->getPhone(), null, $user->getName());

if (!$createdUser) {
$this->logs[Log::ERROR][] = new Log('Failed to import user', \time(), $user);
} else {
// Add more data to the user
$auth->updateName($user->getId(), $user->getUsername());
$auth->updatePhone($user->getId(), $user->getPhone());
$auth->updateEmailVerification($user->getId(), $user->getEmailVerified());
$auth->updatePhoneVerification($user->getId(), $user->getPhoneVerified());
$auth->updateStatus($user->getId(), !$user->getDisabled());
}
} catch (\Exception $e) {
$this->logs[] = new Log(Log::ERROR, $e->getMessage(), \time(), $user);
$this->logs[Log::ERROR][] = new Log($e->getMessage(), \time(), $user);
}
}
}
Expand Down
62 changes: 32 additions & 30 deletions src/Transfer/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,19 @@ class Log {
const INFO = 'info';
const WARNING = 'warning';
const ERROR = 'error';
const FATAL = 'fatal';
const DEBUG = 'debug';

public function __construct(private string $level = Log::INFO, private string $message = '', private int $timestamp = 0, protected Resource $resource = null)
public function __construct(private string $message = '', private int $timestamp = 0, protected Resource|null $resource = null)
{
$timestamp = \time();
}

/**
* Get Level
*
* @returns string
*/
public function getLevel(): string
{
return $this->level;
}

/**
* Set Level
*
* @param string $level
* @returns self
*/
public function setLevel(string $level)
{
$this->level = $level;
return $this;
}

/**
* Get Message
*
* @returns string
*/
public function getMessage()
public function getMessage(): string
{
return $this->message;
}
Expand All @@ -51,7 +29,7 @@ public function getMessage()
* @param string $message
* @returns self
*/
public function setMessage(string $message)
public function setMessage(string $message): self
{
$this->message = $message;
return $this;
Expand All @@ -60,22 +38,46 @@ public function setMessage(string $message)
/**
* Get Timestamp
*
* @returns string
* @returns int
*/
public function getTimestamp()
public function getTimestamp(): int
{
return $this->timestamp;
}

/**
* Set Timestamp
*
* @param string $timestamp
* @param int $timestamp
* @returns self
*/
public function setTimestamp(string $timestamp)
public function setTimestamp(int $timestamp): self
{
$this->timestamp = $timestamp;
return $this;
}

/**
* Get Resource
*
* @returns Resource|null
*/
public function getResource(): ?Resource
{
return $this->resource;
}

/**
* As Array
*
* @returns array
*/
public function asArray(): array
{
return [
'message' => $this->message,
'timestamp' => $this->timestamp,
'resource' => $this->resource ? $this->resource->asArray() : null,
];
}
}
7 changes: 7 additions & 0 deletions src/Transfer/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ public function setId(string $id): self
$this->id = $id;
return $this;
}

/**
* As Array
*
* @returns array
*/
abstract public function asArray(): array;
}
Loading