/** * @param \Skully\App\Models\Setting $oldMe */ public function afterDestroy($oldMe) { if ($this->bean->old('input_type') == "image") { //delete images if (file_exists($oldMe->imagePath())) { FileHelper::removeFolder($oldMe->imagePath()); } } }
public function testDeleteCache() { $app = $this->getApp(); $appTestDir = __DIR__ . '/App/public/default/App/views/test'; if (!file_exists($appTestDir)) { mkdir($appTestDir); } $additionalTestDir = __DIR__ . '/App/anotherpublic/App/views/test'; if (!file_exists($additionalTestDir)) { mkdir($additionalTestDir, 0777, true); } file_put_contents($appTestDir . '/test.tpl', '{$test}'); file_put_contents($additionalTestDir . '/test.tpl', '{$test}'); $app->getTheme()->setDir(realpath(__DIR__ . '/App/anotherpublic'), 'plugin'); $app->getTemplateEngine()->assign('test', 'halo'); ob_start(); $app->runControllerFromRawUrl('test/test'); $output = ob_get_clean(); echo $output . "\n"; $this->assertEquals('halo', $output); $app->getTemplateEngine()->assign('test', 'halo2'); ob_start(); $app->runControllerFromRawUrl('test/test'); $output = ob_get_clean(); echo "output 1: " . $output . "\n"; // Cache not deleted, so it should still display the first value. $this->assertEquals('halo', $output); $app->getTemplateEngine()->assign('test', 'halo2'); // Deleting the cache here. $dir = __DIR__ . '/App/App/smarty'; FileHelper::removeFolder($dir); // looks like removing folder is not enough to invalidate cache, we also need to clearCache. ob_start(); $app->runControllerFromRawUrl('test/test'); $output = ob_get_clean(); echo "output 2: " . $output . "\n"; $this->assertEquals('halo', $output); $app->getTemplateEngine()->clearCache('test/test.tpl'); ob_start(); $app->runControllerFromRawUrl('test/test'); $output = ob_get_clean(); echo "output 3: " . $output . "\n"; $this->assertEquals('halo2', $output); }
public function testSetupGit() { $app = __setupApp(); $console = new Console($app, true); $console->addCommands($app->config('additionalCommands')); $gitpath = realpath(__DIR__ . '/../app/.git-s3'); echo $gitpath; shell_exec('rm -rf ' . $gitpath); $this->assertFalse(file_exists($gitpath)); $commands = $console->getCommands(); function className($item) { return get_class($item); } print_r(array_map('className', $commands)); $output = $console->run("skully:s3 setup:git -f"); echo $output->fetch(); FileHelper::removeFolder($gitpath); $this->assertFalse(file_exists($gitpath)); }
public function destroy() { $helper = $this->setupHelper(); $helper->setMode('item'); if (!empty($_POST)) { try { $this->assignItems($helper); $helper->deleteItem($this->getParam('p'), $this->getParam('id')); FileHelper::removeFolder($this->app->config('basePath') . 'App/smarty/cache'); FileHelper::removeFolder($this->app->config('basePath') . 'App/smarty/templates_c'); $this->setMessage("Item " . $this->getParam('id') . " deleted", 'message'); } catch (\Exception $e) { if (file_exists($helper->getCompletePath($this->getParam('p')))) { $this->setMessage("Item not found", 'error'); } else { $this->setMessage("File not found", 'error'); } } } else { $this->setMessage("Cannot access this page directly", 'error'); } echo json_encode(array('redirect' => $this->app->getRouter()->getUrl($this->indexPath, array('p' => $this->getParam('p'), 'id' => $this->getParam('id'), 'l' => $this->getParam('l'))))); }
public function afterDestroy($oldMe) { $oldId = $this->bean->old("id"); $classname = $this->classname(); /** @var \Skully\App\Models\BaseModel $this */ $imagePath = $this->getApp()->getTheme()->getPublicBasePath() . 'images/' . $classname . '/' . $oldId . '/'; FileHelper::removeFolder($imagePath); }