Skip to content

Commit

Permalink
restore update function for issue #3814
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlan-00 committed Feb 7, 2024
1 parent ab2161f commit db500db
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/Repository/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Ampache\Config\AmpConfig;
use Ampache\Module\Authorization\AccessLevelEnum;
use Ampache\Module\Statistics\Stats;
use Ampache\Module\System\AmpError;
use Ampache\Module\System\Core;
use Ampache\Module\System\Dba;
use Ampache\Module\Util\ObjectTypeToClassNameMapper;
Expand Down Expand Up @@ -512,6 +513,64 @@ public static function get_play_size($user_id): int
return $total;
}

/**
* update
* This function is an all encompassing update function that
* calls the mini ones does all the error checking and all that
* good stuff
* @param array $data
* @return int|false
*/
public function update(array $data)

Check failure on line 524 in src/Repository/Model/User.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.2)

Method Ampache\Repository\Model\User::update() has parameter $data with no value type specified in iterable type array.

Check failure on line 524 in src/Repository/Model/User.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.3)

Method Ampache\Repository\Model\User::update() has parameter $data with no value type specified in iterable type array.
{
if (empty($data['username'])) {
AmpError::add('username', T_('Username is required'));
}

if ($data['password1'] != $data['password2'] && !empty($data['password1'])) {
AmpError::add('password', T_("Passwords do not match"));
}

if (AmpError::occurred()) {
return false;
}

if (!isset($data['fullname_public'])) {
$data['fullname_public'] = false;
}

foreach ($data as $name => $value) {
if ($name == 'password1') {
$name = 'password';
} else {
$value = scrub_in($value);

Check failure on line 546 in src/Repository/Model/User.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.2)

Unable to resolve the template type TType in call to function scrub_in

Check failure on line 546 in src/Repository/Model/User.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.3)

Unable to resolve the template type TType in call to function scrub_in
}

switch ($name) {
case 'password':
case 'access':
case 'email':
case 'username':
case 'fullname':
case 'fullname_public':
case 'website':
case 'state':
case 'city':
case 'catalog_filter_group':
if ($this->$name != $value) {
$function = 'update_' . $name;
$this->$function($value);
}
break;
case 'clear_stats':
Stats::clear($this->id);
break;
}
}

return $this->id;
}

/**
* update_catalog_filter_group
* Set a new filter group catalog filter
Expand Down

0 comments on commit db500db

Please sign in to comment.