Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jan] Add API to backup and restore user data.
- Loading branch information
Showing
4 changed files
with
315 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
/** | ||
* Copyright 2017 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file LICENSE for license information (ASL). If you did | ||
* did not receive this file, see http://www.horde.org/licenses/apache. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @license http://www.horde.org/licenses/apache ASL | ||
* @package Turba | ||
*/ | ||
|
||
namespace Turba\Backup; | ||
|
||
use ArrayIterator; | ||
use EmptyIterator; | ||
use Iterator; | ||
use Turba_Driver; | ||
|
||
/** | ||
* Backup iterator for contacts. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @copyright 2017 Horde LLC | ||
* @license http://www.horde.org/licenses/apache ASL | ||
* @package Turba | ||
*/ | ||
class Contacts implements Iterator | ||
{ | ||
/** | ||
* The driver instance. | ||
* | ||
* @var Turba_Driver | ||
*/ | ||
protected $_driver; | ||
|
||
/** | ||
* The blob attributes. | ||
* | ||
* @var array | ||
*/ | ||
protected $_blobs; | ||
|
||
/** | ||
* The contacts iterator. | ||
* | ||
* @var Iterator | ||
*/ | ||
protected $_list; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param Turba_Driver $driver A driver instance. | ||
*/ | ||
public function __construct(Turba_Driver $driver) | ||
{ | ||
$this->_driver = $driver; | ||
$this->_blobs = array_keys($this->_driver->getBlobs()); | ||
} | ||
|
||
// Iterator methods. | ||
|
||
/** | ||
*/ | ||
public function current() | ||
{ | ||
$current = $this->_list->current(); | ||
if (!$current) { | ||
return false; | ||
} | ||
$hash = $current->getAttributes(); | ||
foreach ($this->_blobs as $blob) { | ||
if (strlen($hash[$blob])) { | ||
$hash[$blob] = base64_encode($hash[$blob]); | ||
} | ||
} | ||
return array( | ||
'addressbook' => $this->_driver->getName(), | ||
'contact' => $hash | ||
); | ||
} | ||
|
||
/** | ||
*/ | ||
public function key() | ||
{ | ||
$current = $this->_list->current(); | ||
if (!$current) { | ||
return false; | ||
} | ||
return $current->getValue('__key'); | ||
} | ||
|
||
/** | ||
*/ | ||
public function next() | ||
{ | ||
$this->_list->next(); | ||
} | ||
|
||
/** | ||
*/ | ||
public function rewind() | ||
{ | ||
if (!isset($this->_driver->map['__owner'])) { | ||
$this->_list = new EmptyIterator(); | ||
return; | ||
} | ||
|
||
$this->_list = new ArrayIterator( | ||
$this->_driver->search(array())->objects | ||
); | ||
} | ||
|
||
/** | ||
*/ | ||
public function valid() | ||
{ | ||
return $this->_list->valid(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters