/** * Delete the asset file on disk * * @param boolean $cascade If true records that depend on this record will also be deleted * @access private */ function beforeDelete($cascade = true) { $this->read(); if (!empty($this->data['Asset']) && is_array($this->data['Asset'])) { $assets = array(); $entries = $this->find('all', array('conditions' => array('Asset.parent_id' => $this->data['Asset']['parent_id'], 'Asset.model' => $this->data['Asset']['model'], 'Asset.foreign_key' => $this->data['Asset']['foreign_key'], 'Asset.field' => $this->data['Asset']['field']))); if (!empty($entries) && is_array($entries)) { foreach ($entries as $entry) { $assets[] = $entry['Asset']['filename']; } } $model = new Object(); $model->id = $this->data['Asset']['foreign_key']; $model->name = $this->data['Asset']['model']; $response = assetDelete($model, $assets); if (is_array($response) && $response['status'] != true) { assetError($this, $response['message'], $response['type']); return false; } } return true; }
/** * Saves the error message to the parent Model validationErrors * * @param object $model Model using this behavior * @param string $message Input the error message * @param string $type See AlertComponent for valid alert types * @access private */ function _setError(&$model, $message, $type = 'notice') { assetError($model, $message, $type); }
/** * test error reporting * * @return void */ function testAssetError() { if (App::import('Component', 'Session')) { $session =& new SessionComponent(); $session->delete('Alerts'); assetError($session, 'Notice Message', 'notice'); $result = $session->check('Alerts.notice'); $this->assertTrue($result); $this->assertTrue(in_array('Notice Message', $session->read('Alerts.notice'))); assetError($session, 'Error Message', 'error'); $result = $session->check('Alerts.error'); $this->assertTrue($result); $this->assertTrue(in_array('Error Message', $session->read('Alerts.error'))); assetError($session, 'Success Message', 'success'); $result = $session->check('Alerts.success'); $this->assertTrue($result); $this->assertTrue(in_array('Success Message', $session->read('Alerts.success'))); $session->delete('Alerts'); unset($session); } }