list.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | class PMXI_File_List extends PMXI_Model_List { |
| 4 | public function __construct() { |
| 5 | parent::__construct(); |
| 6 | $this->setTable(PMXI_Plugin::getInstance()->getTablePrefix() . 'files'); |
| 7 | } |
| 8 | |
| 9 | /** |
| 10 | * Sweep history files in accordance with plugin settings |
| 11 | * @return PMXI_File_List |
| 12 | * @chainable |
| 13 | */ |
| 14 | public function sweepHistory() { |
| 15 | $age = PMXI_Plugin::getInstance()->getOption('history_file_age'); |
| 16 | if ($age > 0) { |
| 17 | $date = new DateTime(); $date->modify('-' . $age . ' day'); |
| 18 | foreach ($this->getBy('registered_on <', $date->format('Y-m-d'))->convertRecords() as $f) { |
| 19 | $f->delete(); |
| 20 | } |
| 21 | } |
| 22 | $count = PMXI_Plugin::getInstance()->getOption('history_file_count'); |
| 23 | if ($count > 0) { |
| 24 | $count_actual = $this->countBy(); |
| 25 | if ($count_actual > $count) foreach ($this->getBy(NULL, 'registered_on', 1, $count_actual - $count)->convertRecords() as $f) { |
| 26 | $f->delete(); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return $this; |
| 31 | } |
| 32 | } |