/**
  * @param User $user
  * @param Usage $usageScanner
  * @param Quota $quotaScanner
  * @param AddStorageHandler $addStorageHandler
  */
 private function createStorage(User $user, Usage $usageScanner, Quota $quotaScanner, AddStorageHandler $addStorageHandler)
 {
     $addStorage = new AddStorage();
     $addStorage->name = $user->name();
     $addStorage->storage = $usageScanner->byUsername($user->name());
     $addStorage->quota = $quotaScanner->byUsername($user->name());
     $addStorageHandler->add($addStorage);
 }
 /**
  * @param AddStorage $addStorage
  */
 public function add(AddStorage $addStorage)
 {
     Assertion::integer($addStorage->storage);
     Assertion::integer($addStorage->quota);
     $storage = Storage::withUserDateUsageQuota(User::named($addStorage->name), new \DateTime(), Bytes::allocateUnits((int) $addStorage->storage), Quota::fromBytes(Bytes::allocateUnits((int) $addStorage->quota)));
     $this->storageRepository->add($storage);
 }
Example #3
0
 /**
  * @return User[]
  */
 public function allUsers()
 {
     $users = [];
     $systemUsers = \OC_User::getUsers();
     foreach ($systemUsers as $uid) {
         $users[] = User::named($uid);
     }
     return $users;
 }
 /**
  * @test
  */
 public function shouldReturnDateSeparatelyOnJsonSerialize()
 {
     $dateTime = new \DateTime("2015-12-31 23:50:01");
     $storage = Storage::withUserDateUsageQuota(User::named('username'), $dateTime, Bytes::allocateUnits(0), Quota::fromBytes(Bytes::allocateUnits(1)));
     $serializedStorage = $storage->jsonSerialize();
     $this->assertSame('2015', $serializedStorage['year']);
     $this->assertSame('12', $serializedStorage['month']);
     $this->assertSame('31', $serializedStorage['day']);
     $this->assertSame('23', $serializedStorage['hour']);
     $this->assertSame('50', $serializedStorage['minute']);
 }
 /**
  * @test
  */
 public function shouldIterateThroughStorages()
 {
     $this->activityCollection->add(Activity::withUserDateActivityCount(User::named('test'), new \DateTime("2015-12-30 23:50:01"), 1));
     $this->activityCollection->add(Activity::withUserDateActivityCount(User::named('test'), new \DateTime("2015-12-31 23:50:01"), 1));
     $this->activityCollection->add(Activity::withUserDateActivityCount(User::named('test'), new \DateTime("2015-12-31 23:50:01"), 1));
     $dates = ['2015-12-30', '2015-12-31'];
     $i = 0;
     foreach ($this->activityCollection as $day => $activity) {
         $this->assertSame($dates[$i], $day);
         $this->assertInstanceOf(Activity::class, $activity);
         $i++;
     }
     $this->assertSame(2, $i);
 }
Example #6
0
 /**
  * @return string
  */
 public function username()
 {
     return $this->user->name();
 }
 /**
  * @param array $row
  * @param string $unitOfMeasurement
  * @return Storage
  */
 private function mapStorageUsageRowToStorage($row, $unitOfMeasurement = 'b')
 {
     $bytes = Bytes::allocateUnits((int) $row['usage']);
     switch ($unitOfMeasurement) {
         case 'gb':
             $bytes = $bytes->gigaBytes();
             break;
         case 'mb':
             $bytes = $bytes->megaBytes();
             break;
         case 'kb':
             $bytes = $bytes->kiloBytes();
             break;
     }
     return Storage::withUserDateUsageQuota(User::named($row['username']), \DateTime::createFromFormat("Y-m-d H:i:s", $row['created']), $bytes, Quota::fromBytes(Bytes::allocateUnits((int) $row['maximumusage'])));
 }
Example #8
0
 /**
  * @test
  */
 public function shouldFailOnEmptyUsername()
 {
     $this->setExpectedException(InvalidArgumentException::class);
     User::named('');
 }
 /**
  * @param array $row
  * @return Activity
  */
 private function mapActivityRowToActivity($row)
 {
     $dateTime = new \DateTime();
     return Activity::withUserDateActivityCount(User::named($row['user']), $dateTime->setTimestamp((int) $row['timestamp']), (int) $row['activities']);
 }
 /**
  * @param StorageCollection $collection
  * @param string $username
  */
 private function addStorageToCollection(StorageCollection $collection, $username)
 {
     $collection->add(Storage::withUserDateUsageQuota(User::named($username), new \DateTime("2015-12-31 23:50:01"), Bytes::allocateUnits(0), Quota::fromBytes(Bytes::allocateUnits(1))));
 }
 /**
  * @test
  * @dataProvider getInvalidActivities
  * @param $activityCount
  */
 public function shouldNotAllowCreationWithoutValidActivityCount($activityCount)
 {
     $this->setExpectedException(InvalidArgumentException::class);
     Activity::withUserDateActivityCount(User::named('test'), new \DateTime("2015-12-31 23:50:01"), $activityCount);
 }