/** * Handle on_project_object_moved event * * @param ProjectObject $object * @param Project $source * @param Project $destination * @return null */ function resources_handle_on_project_object_moved(&$object, &$source, &$destination) { if ($object->can_have_subscribers) { $subscribers = $object->getSubscribers(); if (is_foreachable($subscribers)) { foreach ($subscribers as $subscriber) { if (!$subscriber->isProjectMember($destination)) { Subscriptions::unsubscribe($subscriber, $object); } // if } // foreach } // if } // if $object_ids = array(); // Relations with milestones are carried out via milestone_id field if (instance_of($object, 'Milestone')) { db_execute('UPDATE ' . TABLE_PREFIX . 'project_objects SET milestone_id = 0 WHERE milestone_id = ?', $object->getId()); } // if $rows = db_execute_all('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE type IN (?) AND parent_id = ?', array('task', 'comment', 'attachment', 'timerecord'), $object->getId()); if (is_foreachable($rows)) { foreach ($rows as $row) { $object_ids[] = (int) $row['id']; } // foreach // Sub-objects (attachments for comments, time records for tasks, tasks for tickets) $rows = db_execute_all('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id IN (?)', $object_ids); if (is_foreachable($rows)) { foreach ($rows as $row) { $object_ids[] = (int) $row['id']; } // foreach } // if // Update objects and activity logs db_execute('UPDATE ' . TABLE_PREFIX . 'project_objects SET project_id = ? WHERE id IN (?)', $destination->getId(), $object_ids); db_execute('UPDATE ' . TABLE_PREFIX . 'activity_logs SET project_id = ? WHERE object_id IN (?)', $destination->getId(), $object_ids); // Clear cache cache_remove_by_pattern(TABLE_PREFIX . 'activity_logs_id_*'); cache_remove_by_pattern(TABLE_PREFIX . 'project_objects_id_*'); } // if }
/** * Set $currency as default * * @param Currency $currency * @return boolean */ function setDefault($currency) { if ($currency->getIsDefault()) { return true; } // if db_begin_work(); $currency->setIsDefault(true); $update = $currency->save(); if ($update && !is_error($update)) { $update = db_execute('UPDATE ' . TABLE_PREFIX . 'currencies SET is_default = ? WHERE id != ?', false, $currency->getId()); cache_remove_by_pattern(TABLE_PREFIX . 'currencies_id_*'); if ($update && !is_error($update)) { db_commit(); return true; } // if } // if db_rollback(); return $update; }
public static function removeCacheEntryByPattern($pattern) { $pattern = self::$_cacheKeyPrefix . '_' . $pattern; //var_dump($pattern); cache_remove_by_pattern($pattern); }
/** * Install module * * @param void * @return null */ function install() { if ($this->active_module->isLoaded()) { $this->httpError(HTTP_ERR_CONFLICT, 'Module already installed'); } // if $log = array(); $this->smarty->assign(array('can_be_installed' => $this->active_module->canBeInstalled($log), 'installation_check_log' => $log)); if ($this->request->isSubmitted()) { if ($this->active_module->isLoaded()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $module_name = $this->request->get('module_name'); $this->active_module->setName($module_name); if (!is_dir($this->active_module->getPath())) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $install = $this->active_module->install(); if ($install && !is_error($install)) { cache_remove('all_modules'); cache_remove_by_pattern('lang_cache_for_*'); flash_success(':name module is installed', array('name' => Inflector::humanize($module_name))); } else { flash_error('Failed to install :name module', array('name' => Inflector::humanize($module_name))); } // if $this->redirectToUrl($this->active_module->getViewUrl()); } // if }
/** * Save user into the database * * @param void * @return boolean */ function save() { $modified_fields = $this->modified_fields; $is_new = $this->isNew(); if ($is_new && $this->getToken() == '') { $this->resetToken(); } // if $save = parent::save(); if ($save && !is_error($save)) { if ($is_new || in_array('email', $modified_fields) || in_array('first_name', $modified_fields) || in_array('last_name', $modified_fields)) { $content = $this->getEmail(); if ($this->getFirstName() || $this->getLastName()) { $content .= "\n\n" . trim($this->getFirstName() . ' ' . $this->getLastName()); } // if search_index_set($this->getId(), 'User', $content); cache_remove_by_pattern('object_assignments_*_rendered'); } // if // Role changed? if (in_array('role_id', $modified_fields)) { clean_user_permissions_cache($this); } // if } // if return $save; }
/** * Drop records by project * * @param Project $project * @return boolean */ function deleteByProject($project) { cache_remove_by_pattern('user_pinned_projects_*'); return db_execute('DELETE FROM ' . TABLE_PREFIX . 'pinned_projects WHERE project_id = ?', $project->getId()); }
/** * Set status to related time records * * @param integer $new_status * @return boolean */ function setTimeRecordsStatus($new_status) { $ids = $this->getTimeRecordIds(); if (is_foreachable($ids)) { $update = db_execute('UPDATE ' . TABLE_PREFIX . 'project_objects SET integer_field_2 = ? WHERE id IN (?)', $new_status, $ids); if ($update) { cache_remove_by_pattern(TABLE_PREFIX . 'project_objects_id_*'); return true; } else { return $update; } // if } // if return true; }
/** * Edit translation file in chosen language * * @param void * @return void */ function edit_translation_file() { if ($this->active_language->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $translation_id = $this->request->get('filename'); if (!$translation_id) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $dictionary_filename = Languages::getDictionaryPath($translation_id); if (!is_file($dictionary_filename)) { flash_error('Dictionary does not exists'); $this->redirectToUrl($this->active_language->getViewUrl()); } // if $dictionary = Languages::getDictionary($translation_id); $translation_file = Languages::getTranslationPath($this->active_language, $translation_id); if (!is_file($translation_file)) { flash_error('Translation file does not exists. You need to create it first.'); $this->redirectToUrl($this->active_language->getViewUrl()); } // if $translation_data = Languages::getTranslation($this->active_language, $translation_id); $prepared_form_data = $this->request->post('form_data'); if (!is_array($prepared_form_data)) { $prepared_form_data = array(); foreach ($dictionary as $dictionary_id => $dictionary_value) { $prepared_form_data[$dictionary_id] = array("dictionary_value" => $dictionary_value, "translated_value" => array_var($translation_data, $dictionary_value)); } // foreach $this->smarty->assign(array("prepared_form_data" => $prepared_form_data)); } // if $this->smarty->assign(array("translation_file" => $translation_id, "form_url" => $this->active_language->getEditTranslationFileUrl($translation_id))); if ($this->request->isSubmitted()) { if (is_foreachable($prepared_form_data)) { $new_prepared_data = array(); $translation_data = array(); foreach ($prepared_form_data as $prepared_form_data_key => $prepared_form_data_value) { $translation_data[array_var($dictionary, $prepared_form_data_key)] = $prepared_form_data_value; $new_prepared_data[$prepared_form_data_key] = array("dictionary_value" => array_var($dictionary, $prepared_form_data_key), "translated_value" => $prepared_form_data_value); } // foreach } // if file_put_contents($translation_file, '<?php return ' . var_export($translation_data, true) . ' ?>'); cache_remove_by_pattern('lang_cache_for_*'); if (module_loaded('incoming_mail')) { // set config option for translation if (array_key_exists(EMAIL_SPLITTER, $translation_data)) { $config_option = ConfigOptions::getValue('email_splitter_translations'); $config_option[$this->active_language->getLocale()] = $translation_data[EMAIL_SPLITTER]; ConfigOptions::setValue('email_splitter_translations', $config_option); } // if } // if $this->smarty->assign(array("prepared_form_data" => $new_prepared_data)); } // if }
/** * Clean up assignments cache * * @param void * @return null */ function clean_assignments_cache() { cache_remove_by_pattern('object_assignments_*'); cache_remove_by_pattern('object_assignments_*_rendered'); cache_remove_by_pattern('user_assignments_*'); }
/** * Delete subscriptions by object ID-s * * @param array $ids * @return boolean */ function deleteByObjectIds($ids) { cache_remove_by_pattern('user_subscriptions_*'); return Subscriptions::delete(array('parent_id IN (?)', $ids)); }
/** * Removes object and files from filesystem * * @param void * @return null */ function delete() { $delete = parent::delete(); if ($delete && !is_error($delete)) { recursive_rmdir($this->getLocalizationPath(), LOCALIZATION_PATH); $user_config_options_table = TABLE_PREFIX . 'user_config_options'; $rows = db_execute_all("SELECT user_id, value FROM {$user_config_options_table} WHERE name = ?", 'language'); if (is_foreachable($rows)) { $used_by_users = array(); foreach ($rows as $row) { if (unserialize($row['value']) == $this->getId()) { $used_by_users[] = (int) $row['user_id']; } // if } // foreach if (is_foreachable($used_by_users)) { db_execute("DELETE FROM {$user_config_options_table} WHERE name = ? AND user_id IN (?)", 'language', $used_by_users); cache_remove_by_pattern('user_config_options_*'); } // if } // if } // if return $delete; }
/** * Delete assignemtns by object ID-s * * @param array $ids * @return boolean */ function deleteByObjectIds($ids) { cache_remove_by_pattern('object_assignments_*'); return Assignments::delete(array('object_id IN (?)', $ids)); }