Пример #1
0
 /**
  * @return array
  * @throws \yii\base\InvalidConfigException
  */
 protected function getAllAssignments()
 {
     $result = [];
     $useCache = $this->useCache === true;
     if ($useCache && $this->cache->exists('assignments-0')) {
         echo '    > Assignments cache exists.' . PHP_EOL;
         $answer = $this->prompt('      > Use cache? [yes/no]');
         if (strpos($answer, 'y') === 0) {
             $this->cacheIterator(function ($key) use(&$result) {
                 $result = ArrayHelper::merge($result, $this->cache->get($key));
             });
             return $result;
         }
     }
     /** @var \yii\db\ActiveQuery $UsersQuery */
     $UsersQuery = call_user_func([$this->user->identityClass, 'find']);
     /** @var \yii\web\IdentityInterface[] $Users */
     foreach ($UsersQuery->batch($this->batchSize, $this->db) as $k => $Users) {
         $chunk = [];
         foreach ($Users as $User) {
             $pk = $User->getId();
             $assignments = array_keys($this->authManager->getAssignments($pk));
             $chunk[$pk] = $assignments;
             $result[$pk] = $assignments;
         }
         if ($useCache) {
             $this->cache->set(sprintf('assignments-%d', $k), $chunk);
         }
     }
     return $result;
 }