本文整理汇总了PHP中FileDataManager类的典型用法代码示例。如果您正苦于以下问题:PHP FileDataManager类的具体用法?PHP FileDataManager怎么用?PHP FileDataManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileDataManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteFile
private function deleteFile($file)
{
$file = FileDataManager::getBackupPath($file);
if (file_exists($file)) {
unlink($file);
}
}
示例2: __construct
public function __construct($session_started = false)
{
parent::__construct($session_started);
$this->setViewTemplate('install.backup.tpl');
$this->setPageTitle('Backup & Restore');
$this->backup_file = FileDataManager::getDataPath('.htthinkup_db_backup.zip');
// not in the backup dir itself
}
示例3: tearDown
public function tearDown()
{
$this->builders = null;
$test_email = FileDataManager::getDataPath(Mailer::EMAIL);
if (file_exists($test_email)) {
unlink($test_email);
}
parent::tearDown();
}
示例4: tearDown
public function tearDown()
{
parent::tearDown();
// delete test email file if it exists
$test_email = FileDataManager::getDataPath(Mailer::EMAIL);
if (file_exists($test_email)) {
unlink($test_email);
}
}
示例5: getLastMail
/**
* Return the contents of the last email Mailer "sent" out.
* For testing purposes only; this will return nothing in production.
* @return str The contents of the last email sent
*/
public static function getLastMail()
{
$test_email_file = FileDataManager::getDataPath(Mailer::EMAIL);
if (file_exists($test_email_file)) {
return file_get_contents($test_email_file);
} else {
return '';
}
}
示例6: setUp
public function setUp()
{
parent::setUp();
new BackupMySQLDAO();
$this->config = Config::getInstance();
$this->pdo = BackupMySQLDAO::$PDO;
$this->backup_file = FileDataManager::getDataPath('.htthinkup_db_backup.zip');
$this->backup_test = FileDataManager::getDataPath('thinkup_db_backup_test.zip');
$this->backup_dir = FileDataManager::getBackupPath() . '/';
}
示例7: tearDown
public function tearDown()
{
parent::tearDown();
$config = Config::getInstance();
$config->setValue("mandrill_api_key", "");
// delete test email file if it exists
$test_email = FileDataManager::getDataPath(Mailer::EMAIL);
if (file_exists($test_email)) {
unlink($test_email);
}
}
示例8: tearDown
public function tearDown()
{
parent::tearDown();
$zipfile = FileDataManager::getBackupPath('.htthinkup_db_backup.zip');
$backup_dir = FileDataManager::getBackupPath();
if (file_exists($zipfile)) {
unlink($zipfile);
}
if (file_exists($backup_dir)) {
$this->recursiveDelete($backup_dir);
}
}
示例9: testGetBackupPath
public function testGetBackupPath()
{
require THINKUP_WEBAPP_PATH . 'config.inc.php';
//if test fails here, the config file doesn't have datadir_path set
$this->assertNotNull($THINKUP_CFG['datadir_path']);
//test just path
$path = FileDataManager::getBackupPath();
$this->assertEqual($path, $THINKUP_CFG['datadir_path'] . 'backup/');
//test just path
$path = FileDataManager::getBackupPath('README.txt');
$this->assertEqual($path, $THINKUP_CFG['datadir_path'] . 'backup/README.txt');
}
示例10: testViewManagerDefaultValues
/**
* Test default values
*/
public function testViewManagerDefaultValues()
{
$cfg = Config::getInstance();
$cfg->setValue('source_root_path', '/path/to/thinkup/');
$cfg->setValue('cache_pages', true);
$cfg->setValue('cache_lifetime', 600);
$v_mgr = new ViewManager();
$this->assertTrue(sizeof($v_mgr->template_dir), 2);
$this->assertEqual($v_mgr->template_dir[1], '/path/to/thinkup/tests/view');
$this->assertTrue(sizeof($v_mgr->plugins_dir), 2);
$this->assertEqual($v_mgr->plugins_dir[0], 'plugins');
$this->assertEqual($v_mgr->cache_dir, FileDataManager::getDataPath('compiled_view/cache'));
$this->assertEqual($v_mgr->cache_lifetime, $cfg->getValue('cache_lifetime'));
$this->assertTrue($v_mgr->caching);
}
示例11: testTokenEmailWithSSL
public function testTokenEmailWithSSL()
{
$config = Config::getInstance();
$site_root_path = $config->getValue('site_root_path');
// build 1 valid admin and two invalid admins
$builder1 = FixtureBuilder::build('owners', array('is_admin' => 1, 'is_activated' => 1, 'email' => 'm@w.nz'));
$builder2 = FixtureBuilder::build('owners', array('is_admin' => 0, 'is_activated' => 1, 'email' => 'm2@w.nz'));
$builder3 = FixtureBuilder::build('owners', array('is_admin' => 1, 'is_activated' => 0, 'email' => 'm3@w.nz'));
$_SERVER['HTTP_HOST'] = "mytestthinkup";
$_SERVER['HTTPS'] = "mytestthinkup";
$controller = new UpgradeDatabaseController(true);
$results = $controller->go();
$this->assertTrue(file_exists($this->token_file));
$this->assertPattern('/<!-- we are upgrading -->/', $results);
$this->assertTrue(file_exists($this->token_file));
$token = file_get_contents($this->token_file);
$this->assertPattern('/^[\\da-f]{32}$/', $token);
$email_file = Mailer::getLastMail();
$this->debug($email_file);
$this->assertPattern('/to\\: m@w\\.nz\\s/', $email_file);
$this->assertPattern('/subject\\: Upgrade Your ThinkUp Database/', $email_file);
$token_regex = '/https:\\/\\/mytestthinkup' . str_replace('/', '\\/', $site_root_path) . 'install\\/upgrade-database.php\\?upgrade_token=' . $token . '/';
$this->assertPattern($token_regex, $email_file);
// build 1 more valid admin, should have two to emails
$test_email = FileDataManager::getDataPath(Mailer::EMAIL);
unlink($test_email);
unlink($this->token_file);
$builder4 = FixtureBuilder::build('owners', array('is_admin' => 1, 'is_activated' => 1, 'email' => 'm4@w.nz'));
$results = $controller->go();
$this->assertTrue(file_exists($this->token_file));
$this->assertPattern('/<!-- we are upgrading -->/', $results);
$this->assertTrue(file_exists($this->token_file));
$token = file_get_contents($this->token_file);
$this->assertPattern('/^[\\da-f]{32}$/', $token);
$email_file = Mailer::getLastMail();
$this->assertPattern('/to\\: m@w\\.nz,m4@w\\.nz\\s/', $email_file);
$this->assertPattern('/subject\\: Upgrade Your ThinkUp Database/', $email_file);
$token_regex = '/\\/install\\/upgrade-database.php\\?upgrade_token=' . $token . '/';
$this->assertPattern($token_regex, $email_file);
// should not send email if a token file exists
$test_email = FileDataManager::getDataPath(Mailer::EMAIL);
unlink($test_email);
$results = $controller->go();
$this->assertFalse(file_exists($test_email));
}
示例12: testIsSessionDirectoryWritable
public function testIsSessionDirectoryWritable()
{
//get whatever session save path is set to
$session_save_path = ini_get('session.save_path');
ini_set('session.save_path', FileDataManager::getDataPath());
$installer = Installer::getInstance();
$session_save_permission = $installer->isSessionDirectoryWritable();
$this->assertTrue($session_save_permission);
//reset back to what it was
ini_set('session.save_path', $session_save_path);
}
示例13: export
public function export($backup_file = null)
{
// get table names...
$q = "show tables";
$q2 = "show create table ";
$stmt = $this->execute($q);
$data = $this->getDataRowsAsArrays($stmt);
$create_tables = '';
$zip_file = FileDataManager::getDataPath('.htthinkup_db_backup.zip');
if ($backup_file) {
$zip_file = $backup_file;
}
$zip = new ZipArchive();
if (file_exists($zip_file)) {
unlink($zip_file);
}
// make sure w can create this zip file, ZipArchive is a little funky and wont let us know its status
// until we call close
$zip_create_status = @touch($zip_file);
if ($zip_create_status) {
unlink($zip_file);
}
$backup_dir = FileDataManager::getBackupPath();
if (!$zip_create_status || $zip->open($zip_file, ZIPARCHIVE::CREATE) !== TRUE) {
throw new Exception("Unable to open backup file for exporting: {$zip_file}");
}
// write lock tables...
$table_locks_list = '';
foreach ($data as $table) {
foreach ($table as $key => $value) {
if ($table_locks_list != '') {
$table_locks_list .= ', ';
}
$table_locks_list .= $value . ' WRITE';
}
}
try {
$stmt = $this->execute("LOCK TABLES " . $table_locks_list);
$tmp_table_files = array();
foreach ($data as $table) {
foreach ($table as $key => $value) {
if (getenv('BACKUP_VERBOSE') !== false) {
print " Backing up data for table: {$value}\n";
}
$stmt = $this->execute($q2 . $value);
$create_tables .= "-- Create {$value} table statement\n";
$create_tables .= "DROP TABLE IF EXISTS {$value};\n";
$create_data = $this->getDataRowAsArray($stmt);
$create_tables .= $create_data["Create Table"] . ";";
$create_tables .= "\n\n";
// export table data
$table_file = FileDataManager::getBackupPath($value . '.txt');
if (file_exists($table_file)) {
unlink($table_file);
}
$q3 = "select * INTO OUTFILE '{$table_file}' from {$value}";
$stmt = $this->execute($q3);
$zip->addFile($table_file, "/{$value}" . '.txt');
array_push($tmp_table_files, $table_file);
}
}
} catch (Exception $e) {
$err = $e->getMessage();
if (preg_match("/Can't create\\/write to file/", $err) || preg_match("/Can\\'t get stat of/", $err)) {
// a file perm issue?
throw new OpenFileException("It looks like the MySQL user does not have the proper file permissions " . "to back up data");
} else {
// assume its a GRANT FILE OR LOCK TABLES issue?
throw new MySQLGrantException("It looks like the MySQL user does not have the proper grant permissions " . "to back up data");
}
error_log("export DB OUTFILE error: " . $e->getMessage());
}
// unlock tables...
$stmt = $this->execute("unlock tables");
if (getenv('BACKUP_VERBOSE') !== false) {
print "\n Backing up create table statments\n";
}
$zip->addFromString("create_tables.sql", $create_tables);
$zip_close_status = $zip->close();
// clean up tmp table files
foreach ($tmp_table_files as $tmp_file) {
unlink($tmp_file);
}
if ($zip_close_status == false) {
throw new Exception("Unable to create backup file for exporting. Bad file path?: {$zip_file}");
}
return $zip_file;
}
示例14: generateUpgradeToken
/**
* Generates a one time upgrade token, and emails admins with the token info.
*/
public static function generateUpgradeToken()
{
$token_file = FileDataManager::getDataPath('.htupgrade_token');
$md5_token = '';
if (!file_exists($token_file)) {
$fp = fopen($token_file, 'w');
if ($fp) {
$token = self::TOKEN_KEY . rand(0, time());
$md5_token = md5($token);
if (!fwrite($fp, $md5_token)) {
throw new OpenFileException("Unable to write upgrade token file: " + $token_file);
}
fclose($fp);
} else {
throw new OpenFileException("Unable to create upgrade token file: " + $token_file);
}
// email our admin with this token.
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$admins = $owner_dao->getAdmins();
if ($admins) {
$tos = array();
foreach ($admins as $admin) {
$tos[] = $admin->email;
}
$to = join(',', $tos);
$upgrade_email = new SmartyThinkUp();
$upgrade_email->caching = false;
$server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
//supress test weirdness
$upgrade_email->assign('server', $server);
$upgrade_email->assign('token', $md5_token);
$message = $upgrade_email->fetch('_email.upgradetoken.tpl');
$config = Config::getInstance();
Mailer::mail($to, "Upgrade Your ThinkUp Database", $message);
}
}
}
示例15: testCrawlWithAuthError
public function testCrawlWithAuthError()
{
//build active instance owned by a owner
$instance_with_autherror = array('id' => 5, 'network_username' => 'Liz Lemon', 'network_user_id' => '123456', 'network_viewer_id' => '123456', 'last_post_id' => '0', 'total_posts_in_system' => '0', 'total_replies_in_system' => '0', 'total_follows_in_system' => '0', 'is_archive_loaded_replies' => '0', 'is_archive_loaded_follows' => '0', 'crawler_last_run' => '', 'earliest_reply_in_system' => '', 'avg_replies_per_day' => '2', 'is_public' => '0', 'is_active' => '1', 'network' => 'facebook', 'last_favorite_id' => '0', 'owner_favs_in_system' => '0', 'total_posts_by_owner' => 0, 'posts_per_day' => 1, 'posts_per_week' => 1, 'percentage_replies' => 50, 'percentage_links' => 50, 'earliest_post_in_system' => '2009-01-01 13:48:05', 'favorites_profile' => '0');
$instance_builder_1 = FixtureBuilder::build('instances', $instance_with_autherror);
$builders = array();
$builders[] = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => 'me@example.com', 'is_activated' => 1));
$builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 5, 'auth_error' => ''));
//assert invalid_oauth_email_sent_timestamp option is not set
$option_dao = DAOFactory::getDAO('OptionDAO');
$plugin_dao = DAOFactory::getDAO('PluginDAO');
$plugin_id = $plugin_dao->getPluginId('facebook');
$last_email_timestamp = $option_dao->getOptionByName(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp');
$this->assertNull($last_email_timestamp);
//log in as that owner
$this->simulateLogin('me@example.com');
$_SERVER['HTTP_HOST'] = "mytestthinkup";
//run the crawl
$fb_plugin = new FacebookPlugin();
$fb_plugin->crawl();
//assert that APIOAuthException was caught and recorded in owner_instances table
$owner_instance_dao = new OwnerInstanceMySQLDAO();
$owner_instance = $owner_instance_dao->get(1, 5);
$this->assertEqual($owner_instance->auth_error, 'Error validating access token: Session has expired at unix ' . 'time SOME_TIME. The current unix time is SOME_TIME.');
//assert that the email notification was sent to the user
$expected_reg_email_pattern = '/to: me@example.com
subject: Please re-authorize ThinkUp to access Liz Lemon on Facebook
message: Hi! Your ThinkUp installation is no longer connected to the Liz Lemon Facebook account./';
$actual_reg_email = Mailer::getLastMail();
$this->debug($actual_reg_email);
$this->assertPattern($expected_reg_email_pattern, $actual_reg_email);
//assert invalid_oauth_email_sent_timestamp option has been set
$last_email_timestamp = $option_dao->getOptionByName(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp');
$this->assertNotNull($last_email_timestamp);
//Delete last mail file
$test_email_file = FileDataManager::getDataPath(Mailer::EMAIL);
unlink($test_email_file);
$actual_reg_email = Mailer::getLastMail();
//Assert it's been deleted
$this->assertEqual($actual_reg_email, '');
//Crawl again
$fb_plugin->crawl();
//Assert email has not been resent
$actual_reg_email = Mailer::getLastMail();
$this->debug($actual_reg_email);
$this->assertEqual($actual_reg_email, '');
}