feat: update appwrite image
This commit is contained in:
parent
65c6123ccd
commit
f6ae33aeba
1 changed files with 68 additions and 62 deletions
|
@ -14,8 +14,6 @@ use Utopia\Analytics\Adapter\Mixpanel;
|
||||||
use Utopia\Analytics\Event;
|
use Utopia\Analytics\Event;
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Pools\Group;
|
use Utopia\Pools\Group;
|
||||||
use Utopia\Pools\Pool;
|
|
||||||
use Utopia\Registry\Registry;
|
|
||||||
|
|
||||||
class Hamster extends Action
|
class Hamster extends Action
|
||||||
{
|
{
|
||||||
|
@ -325,52 +323,56 @@ class Hamster extends Action
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->calculateByGroup('teams', $dbForConsole, function (Database $dbForConsole, Document $document) {
|
$this->calculateByGroup('teams', $dbForConsole, function (Database $dbForConsole, Document $document) {
|
||||||
$statsPerOrganization = [];
|
try {
|
||||||
|
$statsPerOrganization = [];
|
||||||
|
|
||||||
/** Organization name */
|
/** Organization name */
|
||||||
$statsPerOrganization['name'] = $document->getAttribute('name');
|
$statsPerOrganization['name'] = $document->getAttribute('name');
|
||||||
|
|
||||||
/** Get Email and of the organization owner */
|
/** Get Email and of the organization owner */
|
||||||
$membership = $dbForConsole->findOne('memberships', [
|
$membership = $dbForConsole->findOne('memberships', [
|
||||||
Query::equal('teamInternalId', [$document->getInternalId()]),
|
Query::equal('teamInternalId', [$document->getInternalId()]),
|
||||||
]);
|
|
||||||
|
|
||||||
if (!$membership || $membership->isEmpty()) {
|
|
||||||
throw new Exception('Membership not found. Skipping organization : ' . $document->getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
$userInternalId = $membership->getAttribute('userInternalId', null);
|
|
||||||
if ($userInternalId) {
|
|
||||||
$user = $dbForConsole->findOne('users', [
|
|
||||||
Query::equal('_id', [$userInternalId]),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$statsPerOrganization['email'] = $user->getAttribute('email', null);
|
if (!$membership || $membership->isEmpty()) {
|
||||||
}
|
throw new Exception('Membership not found. Skipping organization : ' . $document->getId());
|
||||||
|
}
|
||||||
|
|
||||||
/** Organization Creation Date */
|
$userInternalId = $membership->getAttribute('userInternalId', null);
|
||||||
$statsPerOrganization['created'] = $document->getAttribute('$createdAt');
|
if ($userInternalId) {
|
||||||
|
$user = $dbForConsole->findOne('users', [
|
||||||
|
Query::equal('_id', [$userInternalId]),
|
||||||
|
]);
|
||||||
|
|
||||||
/** Number of team members */
|
$statsPerOrganization['email'] = $user->getAttribute('email', null);
|
||||||
$statsPerOrganization['members'] = $document->getAttribute('total');
|
}
|
||||||
|
|
||||||
/** Number of projects in this organization */
|
/** Organization Creation Date */
|
||||||
$statsPerOrganization['projects'] = $dbForConsole->count('projects', [
|
$statsPerOrganization['created'] = $document->getAttribute('$createdAt');
|
||||||
Query::equal('teamId', [$document->getId()]),
|
|
||||||
Query::limit(APP_LIMIT_COUNT)
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!isset($statsPerOrganization['email'])) {
|
/** Number of team members */
|
||||||
throw new Exception('Email not found. Skipping organization : ' . $document->getId());
|
$statsPerOrganization['members'] = $document->getAttribute('total');
|
||||||
}
|
|
||||||
|
|
||||||
$event = new Event();
|
/** Number of projects in this organization */
|
||||||
$event
|
$statsPerOrganization['projects'] = $dbForConsole->count('projects', [
|
||||||
->setName('Organization Daily Usage')
|
Query::equal('teamId', [$document->getId()]),
|
||||||
->setProps($statsPerOrganization);
|
Query::limit(APP_LIMIT_COUNT)
|
||||||
$res = $this->mixpanel->createEvent($event);
|
]);
|
||||||
if (!$res) {
|
|
||||||
throw new Exception('Failed to create event for organization : ' . $document->getId());
|
if (!isset($statsPerOrganization['email'])) {
|
||||||
|
throw new Exception('Email not found. Skipping organization : ' . $document->getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
$event = new Event();
|
||||||
|
$event
|
||||||
|
->setName('Organization Daily Usage')
|
||||||
|
->setProps($statsPerOrganization);
|
||||||
|
$res = $this->mixpanel->createEvent($event);
|
||||||
|
if (!$res) {
|
||||||
|
throw new Exception('Failed to create event for organization : ' . $document->getId());
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Console::error($e->getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -378,36 +380,40 @@ class Hamster extends Action
|
||||||
protected function getStatsPerUser(Database $dbForConsole)
|
protected function getStatsPerUser(Database $dbForConsole)
|
||||||
{
|
{
|
||||||
$this->calculateByGroup('users', $dbForConsole, function (Database $dbForConsole, Document $document) {
|
$this->calculateByGroup('users', $dbForConsole, function (Database $dbForConsole, Document $document) {
|
||||||
$statsPerUser = [];
|
try {
|
||||||
|
$statsPerUser = [];
|
||||||
|
|
||||||
/** Organization name */
|
/** Organization name */
|
||||||
$statsPerUser['name'] = $document->getAttribute('name');
|
$statsPerUser['name'] = $document->getAttribute('name');
|
||||||
|
|
||||||
/** Organization ID (needs to be stored as an email since mixpanel uses the email attribute as a distinctID) */
|
/** Organization ID (needs to be stored as an email since mixpanel uses the email attribute as a distinctID) */
|
||||||
$statsPerUser['email'] = $document->getAttribute('email');
|
$statsPerUser['email'] = $document->getAttribute('email');
|
||||||
|
|
||||||
/** Organization Creation Date */
|
/** Organization Creation Date */
|
||||||
$statsPerUser['created'] = $document->getAttribute('$createdAt');
|
$statsPerUser['created'] = $document->getAttribute('$createdAt');
|
||||||
|
|
||||||
/** Number of teams this user is a part of */
|
/** Number of teams this user is a part of */
|
||||||
$statsPerUser['memberships'] = $dbForConsole->count('memberships', [
|
$statsPerUser['memberships'] = $dbForConsole->count('memberships', [
|
||||||
Query::equal('userInternalId', [$document->getInternalId()]),
|
Query::equal('userInternalId', [$document->getInternalId()]),
|
||||||
Query::limit(APP_LIMIT_COUNT)
|
Query::limit(APP_LIMIT_COUNT)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!isset($statsPerUser['email'])) {
|
if (!isset($statsPerUser['email'])) {
|
||||||
throw new Exception('User has no email: ' . $document->getId());
|
throw new Exception('User has no email: ' . $document->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Send data to mixpanel */
|
/** Send data to mixpanel */
|
||||||
$event = new Event();
|
$event = new Event();
|
||||||
$event
|
$event
|
||||||
->setName('User Daily Usage')
|
->setName('User Daily Usage')
|
||||||
->setProps($statsPerUser);
|
->setProps($statsPerUser);
|
||||||
$res = $this->mixpanel->createEvent($event);
|
$res = $this->mixpanel->createEvent($event);
|
||||||
|
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
throw new Exception('Failed to create user profile for user: ' . $document->getId());
|
throw new Exception('Failed to create user profile for user: ' . $document->getId());
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Console::error($e->getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue