EMAIL, 'password_hash' => $hash, 'full_name' => FULL_NAME, 'role' => GLOBAL_ROLE, 'consulting_firm_id' => FIRM_ID, 'is_active' => 1, 'email_verified_at' => date('Y-m-d H:i:s'), 'password_version' => 1, ]); $report['user'] = "CREATO (id={$userId}, role=" . GLOBAL_ROLE . ', locale)'; $report['password'] = 'impostata'; } // Verifica hash $chk = Database::fetchOne('SELECT password_hash FROM users WHERE id = ?', [$userId]); $report['password_verify'] = password_verify(PASSWORD, $chk['password_hash']) ? 'OK ✓' : 'FALLITO ✗'; // 2) Membership org 129 $m = Database::fetchOne('SELECT id, role FROM user_organizations WHERE user_id = ? AND organization_id = ?', [$userId, ORG_ID]); if ($m) { $report['membership'] = "già presente (role={$m['role']})"; } else { Database::insert('user_organizations', [ 'user_id' => $userId, 'organization_id' => ORG_ID, 'role' => ORG_ROLE, 'is_primary' => IS_PRIMARY, ]); $report['membership'] = 'AGGIUNTA (org 129, role=' . ORG_ROLE . ')'; } echo "=== Risultato ===\n"; foreach ($report as $k => $v) printf(" %-16s %s\n", $k . ':', $v); // 3) Stato finale membri org 129 echo "\n=== Membri attuali org 129 ===\n"; $rows = Database::fetchAll( 'SELECT uo.user_id, u.full_name, u.email, uo.role, uo.is_primary FROM user_organizations uo JOIN users u ON u.id = uo.user_id WHERE uo.organization_id = ? ORDER BY uo.is_primary DESC, uo.user_id', [ORG_ID]); foreach ($rows as $r) { printf(" #%d %-22s %-32s %-14s %s\n", $r['user_id'], $r['full_name'], $r['email'], $r['role'], $r['is_primary'] ? '(primario)' : ''); }