Skip to content

Commit 148d19b

Browse files
committed
Some extra debug logging to help with fixes testing
1 parent 6c501cc commit 148d19b

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

app/Classes/LDAP/Import.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Classes\LDAP;
44

55
use Illuminate\Support\Collection;
6+
use Illuminate\Support\Facades\Log;
67
use LdapRecord\LdapRecordException;
78

89
use App\Exceptions\Import\GeneralException;
@@ -16,6 +17,8 @@
1617
*/
1718
abstract class Import
1819
{
20+
private const LOGKEY = 'aI-';
21+
1922
// Valid LDIF commands
2023
protected const LDAP_IMPORT_ADD = 1;
2124
protected const LDAP_IMPORT_DELETE = 2;
@@ -57,6 +60,8 @@ final protected function commit(Entry $o,int $action): Collection
5760
$o->save();
5861

5962
} catch (LdapRecordException $e) {
63+
Log::error(sprintf('%s:Import Commit Error',self::LOGKEY),['e'=>$e->getMessage(),'detailed'=>$e->getDetailedError()]);
64+
6065
if ($e->getDetailedError())
6166
return collect([
6267
'dn'=>$o->getDN(),
@@ -76,6 +81,8 @@ final protected function commit(Entry $o,int $action): Collection
7681
]);
7782
}
7883

84+
Log::debug(sprintf('%s:Import Commited',self::LOGKEY));
85+
7986
return collect(['dn'=>$o->getDN(),'result'=>__('Created')]);
8087

8188
default:

app/Classes/LDAP/Import/LDIF.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function process(): Collection
3535
// @todo When renaming DNs, the hotlink should point to the new entry on success, or the old entry on failure.
3636
foreach (preg_split('/(\r?\n|\r)/',$this->input) as $line) {
3737
$c++;
38-
Log::debug(sprintf('%s: LDIF Line [%s]',self::LOGKEY,$line));
38+
Log::debug(sprintf('%s:LDIF Line [%s]',self::LOGKEY,$line));
3939
$line = trim($line);
4040

4141
// If the line starts with a comment, ignore it
@@ -48,7 +48,7 @@ public function process(): Collection
4848
// Add the last attribute;
4949
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
5050

51-
Log::debug(sprintf('%s: Committing Entry [%s]',self::LOGKEY,$o->getDN()));
51+
Log::debug(sprintf('%s:- Committing Entry [%s]',self::LOGKEY,$o->getDN()));
5252

5353
// Commit
5454
$result->push($this->commit($o,$action));
@@ -95,7 +95,7 @@ public function process(): Collection
9595
// If $m is NULL, then this is the 2nd (or more) line of a base64 encoded value
9696
if (! $m) {
9797
$value .= $line;
98-
Log::debug(sprintf('%s: Attribute [%s] adding [%s] (%d)',self::LOGKEY,$attribute,$line,$c));
98+
Log::debug(sprintf('%s:- Attribute [%s] adding [%s] (%d)',self::LOGKEY,$attribute,$line,$c));
9999

100100
// add to last attr value
101101
continue 2;
@@ -108,7 +108,7 @@ public function process(): Collection
108108
throw new GeneralException(sprintf('Previous Entry not complete? (line %d)',$c));
109109

110110
$dn = $base64encoded ? base64_decode($value) : $value;
111-
Log::debug(sprintf('%s: Creating new entry:',self::LOGKEY,$dn));
111+
Log::debug(sprintf('%s:Creating new entry:',self::LOGKEY,$dn));
112112
//$o = Entry::find($dn);
113113

114114
// If it doesnt exist, we'll create it
@@ -120,7 +120,7 @@ public function process(): Collection
120120
$action = self::LDAP_IMPORT_ADD;
121121

122122
} else {
123-
Log::debug(sprintf('%s: Adding Attribute [%s] value [%s] (%d)',self::LOGKEY,$attribute,$value,$c));
123+
Log::debug(sprintf('%s:Adding Attribute [%s] value [%s] (%d)',self::LOGKEY,$attribute,$value,$c));
124124

125125
if ($value)
126126
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
@@ -134,7 +134,7 @@ public function process(): Collection
134134
$attribute = $m[1];
135135
$value = $m[3];
136136

137-
Log::debug(sprintf('%s: New Attribute [%s] with [%s] (%d)',self::LOGKEY,$attribute,$value,$c));
137+
Log::debug(sprintf('%s:- New Attribute [%s] with [%s] (%d)',self::LOGKEY,$attribute,$value,$c));
138138
}
139139

140140
if ($version !== 1)
@@ -146,7 +146,7 @@ public function process(): Collection
146146
// Add the last attribute;
147147
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
148148

149-
Log::debug(sprintf('%s: Committing Entry [%s]',self::LOGKEY,$o->getDN()));
149+
Log::debug(sprintf('%s:- Committing Entry [%s]',self::LOGKEY,$o->getDN()));
150150

151151
// Commit
152152
$result->push($this->commit($o,$action));

app/Classes/LDAP/Server.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private static function cacheflush(string $dn): bool
204204
default => TRUE,
205205
};
206206

207-
Log::debug(sprintf('%s:%s - %s',self::LOGKEY,$cache ? 'Caching' : 'Not Cached',$dn));
207+
Log::debug(sprintf('%s:%s - %s',self::LOGKEY,$cache ? 'DN CACHEABLE' : 'DN NOT cacheable',$dn));
208208
return $cache;
209209
}
210210

@@ -216,7 +216,7 @@ private static function cacheflush(string $dn): bool
216216
private static function cachetime(): Carbon
217217
{
218218
return Carbon::now()
219-
->addSeconds(Config::get('ldap.cache.time'));
219+
->addSeconds(Config::get('ldap.cache.time') ?: 0);
220220
}
221221

222222
/**
@@ -232,7 +232,8 @@ private static function get(string $dn,array $attrs=['*','+']): Builder
232232
->setDN($dn)
233233
->cache(
234234
until: self::cachetime(),
235-
flush: self::cacheflush($dn))
235+
flush: self::cacheflush($dn)
236+
)
236237
->select($attrs);
237238
}
238239

app/Http/Controllers/HomeController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Support\Facades\Auth;
99
use Illuminate\Support\Facades\Crypt;
1010
use Illuminate\Support\Facades\File;
11+
use Illuminate\Support\Facades\Log;
1112
use Illuminate\Support\Facades\Redirect;
1213
use LdapRecord\Exceptions\InsufficientAccessException;
1314
use LdapRecord\LdapRecordException;
@@ -435,6 +436,7 @@ public function import(ImportRequest $request,string $type): \Illuminate\View\Vi
435436
switch ($type) {
436437
case 'ldif':
437438
$import = new LDIFImport($x=($request->text ?: $request->file->get()));
439+
Log::debug('Processing LDIF import',['data'=>$x,'import'=>$import]);
438440
break;
439441

440442
default:

app/Ldap/Entry.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Support\Facades\Crypt;
77
use LdapRecord\Support\Arr;
88
use LdapRecord\Models\Model;
9-
use LdapRecord\Query\Model\Builder;
109

1110
use App\Classes\LDAP\Attribute;
1211
use App\Classes\LDAP\Attribute\Factory;

0 commit comments

Comments
 (0)