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
217 additions
and
2 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,99 @@ | ||
<?php | ||
/** | ||
* Copyright 2017 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (GPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/gpl. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @license http://www.horde.org/licenses/gpl GPL | ||
* @package Nag | ||
*/ | ||
|
||
namespace Nag\Backup; | ||
|
||
use Iterator; | ||
use Nag; | ||
use Nag_Driver; | ||
|
||
/** | ||
* Backup iterator for tasks. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @copyright 2017 Horde LLC | ||
* @license http://www.horde.org/licenses/gpl GPL | ||
* @package Nag | ||
*/ | ||
class Tasks implements Iterator | ||
{ | ||
/** | ||
* The driver instance. | ||
* | ||
* @var Nag_Driver | ||
*/ | ||
protected $_driver; | ||
|
||
/** | ||
* Tasks iterator. | ||
* | ||
* @var Nag_Task | ||
*/ | ||
protected $_task; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param Nag_Driver $driver A driver instance. | ||
*/ | ||
public function __construct(Nag_Driver $driver) | ||
{ | ||
$this->_driver = $driver; | ||
} | ||
|
||
// Iterator methods. | ||
|
||
/** | ||
*/ | ||
public function current() | ||
{ | ||
if (!$this->_current) { | ||
return false; | ||
} | ||
$hash = $this->_current->toHash(); | ||
if ($hash['recurrence']) { | ||
$hash['recurrence'] = $hash['recurrence']->toHash(); | ||
} | ||
return $hash; | ||
} | ||
|
||
/** | ||
*/ | ||
public function key() | ||
{ | ||
return $this->_current ? $this->_current->id : false; | ||
} | ||
|
||
/** | ||
*/ | ||
public function next() | ||
{ | ||
$this->_current = $this->_task->each(); | ||
} | ||
|
||
/** | ||
*/ | ||
public function rewind() | ||
{ | ||
$this->_driver->retrieve(Nag::VIEW_ALL, false); | ||
$this->_task = $this->_driver->tasks; | ||
$this->_task->reset(); | ||
$this->_current = $this->_task->each(); | ||
} | ||
|
||
/** | ||
*/ | ||
public function valid() | ||
{ | ||
return $this->_current !== false; | ||
} | ||
} |
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